Skip to content

Commit

Permalink
refactor: Apply ESLint autofix after config change
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 12, 2024
1 parent 8e9ce60 commit e517f12
Show file tree
Hide file tree
Showing 52 changed files with 854 additions and 872 deletions.
22 changes: 11 additions & 11 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export default {
"extensions": {
"ts": "module"
extensions: {
ts: "module",
},
"files": [
"test/lib/**/*.ts"
files: [
"test/lib/**/*.ts",
],
"watcher": {
"ignoreChanges": [
watcher: {
ignoreChanges: [
"test/tmp/**",
"lib/**"
]
"lib/**",
],
},
"nodeArguments": [
nodeArguments: [
"--import=tsx/esm",
"--no-warnings=ExperimentalWarning"
"--no-warnings=ExperimentalWarning",
],
"workerThreads": false
workerThreads: false,
};
3 changes: 1 addition & 2 deletions scripts/metadataProvider/MetadataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createSemanticModel} from "./model.js";

import {
findSymbol
findSymbol,
} from "@ui5-language-assistant/semantic-model";
import {
BaseUI5Node,
Expand Down Expand Up @@ -46,4 +46,3 @@ export default class MetadataProvider {
return classMetadata.defaultAggregation?.name;
}
}

6 changes: 3 additions & 3 deletions scripts/metadataProvider/createMetadataInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {writeFile} from "node:fs/promises";
import MetadataProvider from "./MetadataProvider";

import {
forEachSymbol
forEachSymbol,
} from "@ui5-language-assistant/semantic-model";

async function main(apiJsonsRoot: string, sapui5Version: string) {
Expand All @@ -22,9 +22,9 @@ async function main(apiJsonsRoot: string, sapui5Version: string) {
const apiExtract = {
framework: {
name: "SAPUI5",
version: sapui5Version
version: sapui5Version,
},
defaultAggregations
defaultAggregations,
};

await writeFile(
Expand Down
16 changes: 8 additions & 8 deletions scripts/metadataProvider/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import {
TypeNameFix,
} from "@ui5-language-assistant/semantic-model";
import {
UI5SemanticModel
UI5SemanticModel,
} from "@ui5-language-assistant/semantic-model-types";

interface ApiJson {
library: string
library: string;
}

function getTypeNameFix(): TypeNameFix {
// From https://github.com/SAP/ui5-language-assistant/blob/44114f34de59e8d415b06b470be6fa3697c7414c/packages/context/src/ui5-model.ts#L229
const fixes: TypeNameFix = {
Control: "sap.ui.core.Control",
Element: "sap.ui.core.Element",
array: "object[]",
Array: "object[]",
bloolean: "boolean",
any: "any",
"Control": "sap.ui.core.Control",
"Element": "sap.ui.core.Element",
"array": "object[]",
"Array": "object[]",
"bloolean": "boolean",
"any": "any",
"sap.m.PlanningCalendarHeader": undefined,
"sap.m.TimePickerSlider": undefined,
"sap.ui.layout.ResponsiveSplitterPage": undefined,
Expand Down
12 changes: 6 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import {hideBin} from "yargs/helpers";
import base from "./cli/base.js";
import { fileURLToPath } from "node:url";
import { setVersion } from "./cli/version.js";
import { createRequire } from "module";
import {fileURLToPath} from "node:url";
import {setVersion} from "./cli/version.js";
import {createRequire} from "module";

export default async function () {
const cli = yargs(hideBin(process.argv));
cli.parserConfiguration({
"parse-numbers": false
"parse-numbers": false,
});

// Explicitly set CLI version as the yargs default might
// be wrong in case a local CLI installation is used
// Also add CLI location
const require = createRequire(import.meta.url);
const pkg = require("../package.json") as { version: string };
const pkg = require("../package.json") as {version: string};
const ui5LintJsPath = fileURLToPath(new URL("../bin/ui5lint.js", import.meta.url));
const pkgVersion = `${pkg.version} (from ${ui5LintJsPath})`;

Expand Down
43 changes: 21 additions & 22 deletions src/cli/base.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Argv, ArgumentsCamelCase} from "yargs";
import path from "node:path";
import { lintProject } from "../linter/linter.js";
import { Text } from "../formatter/text.js";
import { Json } from "../formatter/json.js";
import { Coverage } from "../formatter/coverage.js";
import { writeFile } from "node:fs/promises";
import {lintProject} from "../linter/linter.js";
import {Text} from "../formatter/text.js";
import {Json} from "../formatter/json.js";
import {Coverage} from "../formatter/coverage.js";
import {writeFile} from "node:fs/promises";
import baseMiddleware from "./middlewares/base.js";
import chalk from "chalk";
import { isLogLevelEnabled } from "@ui5/logger";
import {isLogLevelEnabled} from "@ui5/logger";
import ConsoleWriter from "@ui5/logger/writers/Console";

const lintCommand = {
Expand All @@ -19,49 +19,49 @@ const lintCommand = {
cli.usage("Usage: $0 [options]")
.option("file-paths", {
describe: "",
type: "string"
type: "string",
})
.array("file-paths")
.option("coverage", {
describe: "Whether to provide a coverage report",
type: "boolean"
type: "boolean",
})
.option("details", {
describe: "Print complementary information for each finding, if available",
type: "boolean"
type: "boolean",
})
.option("loglevel", {
alias: "log-level",
describe: "Set the logging level",
default: "info",
type: "string",
choices: ["silent", "error", "warn", "info", "perf", "verbose", "silly"]
choices: ["silent", "error", "warn", "info", "perf", "verbose", "silly"],
})
.option("verbose", {
describe: "Enable verbose logging.",
default: false,
type: "boolean"
type: "boolean",
})
.option("perf", {
describe: "Enable performance measurements and related logging.",
default: false,
type: "boolean"
type: "boolean",
})
.option("silent", {
describe: "Disable all log output.",
default: false,
type: "boolean"
type: "boolean",
})
.option("format", {
alias: "f",
describe: "Set the output format for the linter result",
default: "stylish",
type: "string",
choices: ["stylish", "json"]
choices: ["stylish", "json"],
})
.coerce([
// base.js
"log-level"
"log-level",
], (arg) => {
// If an option is specified multiple times, yargs creates an array for all the values,
// independently of whether the option is of type "array" or "string".
Expand All @@ -84,16 +84,16 @@ const lintCommand = {
"Execute command with scope of file-paths");

return cli;
}
},
};

async function handleLint(argv: ArgumentsCamelCase) {
const {
coverage,
filePaths,
details,
format
} = <{ coverage: boolean, filePaths: string[], details: boolean, format: string }><unknown>argv;
format,
} = (argv as unknown) as {coverage: boolean; filePaths: string[]; details: boolean; format: string};

let profile;
if (process.env.UI5LINT_PROFILE) {
Expand All @@ -114,7 +114,6 @@ async function handleLint(argv: ArgumentsCamelCase) {
if (format === "json") {
const jsonFormatter = new Json();
process.stdout.write(jsonFormatter.format(res, details));

} else if (format === "" || format === "stylish") {
const textFormatter = new Text();
process.stderr.write(textFormatter.format(res, details));
Expand Down Expand Up @@ -159,19 +158,19 @@ export default function base(cli: Argv) {
chalk.dim(
`If you think this is an issue of the ui5-linter, you might report it using the ` +
`following URL: `) +
chalk.dim.bold.underline(`https://github.com/SAP/ui5-linter/issues/new/choose`)+"\n");
chalk.dim.bold.underline(`https://github.com/SAP/ui5-linter/issues/new/choose`) + "\n");
} else {
process.stderr.write("\n");
process.stderr.write(chalk.dim(`For details, execute the same command again with an` +
` additional '--verbose' parameter`) + "\n");
` additional '--verbose' parameter`) + "\n");
}
}
} else {
// Yargs error
process.stderr.write(chalk.bold.yellow("Command Failed:\n"));
process.stderr.write(`${msg}\n`);
process.stderr.write("\n");
process.stderr.write(chalk.dim(`See 'ui5lint --help'`)+"\n");
process.stderr.write(chalk.dim(`See 'ui5lint --help'`) + "\n");
}
process.exit(1);
});
Expand Down
4 changes: 2 additions & 2 deletions src/cli/middlewares/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initLogger } from "./logger.js";
import type { ArgumentsCamelCase } from "yargs";
import {initLogger} from "./logger.js";
import type {ArgumentsCamelCase} from "yargs";
/**
* Base middleware for CLI commands.
*
Expand Down
4 changes: 2 additions & 2 deletions src/cli/middlewares/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {setLogLevel, isLogLevelEnabled, getLogger} from "@ui5/logger";
import ConsoleWriter from "@ui5/logger/writers/Console";
import {getVersion} from "../version.js";
import type { ArgumentsCamelCase } from "yargs";
import type {ArgumentsCamelCase} from "yargs";
/**
* Logger middleware to enable logging capabilities
*
Expand All @@ -21,7 +21,7 @@ export async function initLogger(argv: ArgumentsCamelCase) {
// argv.loglevel defaults to "info", which is anyways already the Logger's default
// Therefore do not explicitly set it again in order to allow overwriting the log level
// using the UI5_LOG_LVL environment variable
setLogLevel(<string>argv.loglevel);
setLogLevel((argv.loglevel as string));
}

// Initialize writer
Expand Down
12 changes: 6 additions & 6 deletions src/cli/utils/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {getLogger} from "@ui5/logger";
const log = getLogger("cli:utils:profile");

let session: Session | null;
type ProcessSignals = Record<string, (exitCode: number) => void>
type ProcessSignals = Record<string, (exitCode: number) => void>;
let processSignals: ProcessSignals | null;

export async function start() {
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function stop() {

function registerSigHooks() {
function createListener(exitCode: number) {
return function() {
return function () {
// Gracefully end profiling, then exit
stop().then(() => {
process.exit(exitCode);
Expand All @@ -79,10 +79,10 @@ function registerSigHooks() {
}

const processSignals: ProcessSignals = {
"SIGHUP": createListener(128 + 1),
"SIGINT": createListener(128 + 2),
"SIGTERM": createListener(128 + 15),
"SIGBREAK": createListener(128 + 21)
SIGHUP: createListener(128 + 1),
SIGINT: createListener(128 + 2),
SIGTERM: createListener(128 + 15),
SIGBREAK: createListener(128 + 21),
};

for (const signal of Object.keys(processSignals)) {
Expand Down
Loading

0 comments on commit e517f12

Please sign in to comment.