Skip to content

Commit

Permalink
[eslint-plugin] upgrade typescript-eslint to v8
Browse files Browse the repository at this point in the history
***NO_CI***

- bump typescript-eslint dependencies version to ~8.2.0

- [eslint-plugin] suppress new linting errors appearing with v8

- [eslint-plugin] react to removed typescript-eslint property

  related PR typescript-eslint/typescript-eslint#9025

- [eslint-plugin] turn off @typescript-eslint/no-unused-expressions

  as no-unused-expressions is already reported by eslint

- [dev-tool] fix new linting errors

- Remove @typescript-eslint/ban-types that no longer exists

  and replace with more specific rules wherever applicable.

- [cosmosdb] combine the test eslint config with the main one

- delete catch expression when caught error is not used

- fix or suppress linting errors in code files
  • Loading branch information
jeremymeng committed Aug 23, 2024
1 parent 277798e commit 2ce3c5f
Show file tree
Hide file tree
Showing 88 changed files with 186 additions and 219 deletions.
162 changes: 79 additions & 83 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion common/tools/dev-tool/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import typescriptEsLint from "typescript-eslint";

export default typescriptEsLint.config(
{
ignores: ["**/test/samples/files/expectations/**/*.*"],
ignores: ["**/test/samples/files/expectations/**/*.*", "**/*.{js,cjs,mjs}"],
},
{
languageOptions: {
Expand All @@ -20,6 +20,7 @@ export default typescriptEsLint.config(
{
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-require-imports": "off",
},
},
);
2 changes: 1 addition & 1 deletion common/tools/dev-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"eslint": "^8.0.0",
"mkdirp": "^3.0.1",
"rimraf": "^5.0.5",
"typescript-eslint": "~7.16.0",
"typescript-eslint": "~8.2.0",
"vitest": "^2.0.5"
}
}
11 changes: 8 additions & 3 deletions common/tools/dev-tool/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ async function onMigrationSuccess(

await git.commitAll(`${project.name}: applied migration '${migration.id}'`);

!quiet && log.success(`Migration '${migration.id}' applied successfully.`);
if (!quiet) {
log.success(`Migration '${migration.id}' applied successfully.`);
}
}

/**
Expand All @@ -376,7 +378,9 @@ async function onMigrationSkipped(

await git.commitAll(`${project.name}: skipped migration '${migration.id}'`);

!quiet && log.info(`Skipped migration '${migration.id}'. This package is not eligible.`);
if (!quiet) {
log.info(`Skipped migration '${migration.id}'. This package is not eligible.`);
}
}

/**
Expand Down Expand Up @@ -456,10 +460,11 @@ async function abortMigration(

await removeMigrationStateFile();

!quiet &&
if (!quiet) {
log.warn(
`Suspended migration '${suspendedMigration.id}' was aborted. The working tree may be dirty.`,
);
}

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion common/tools/dev-tool/src/util/customization/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function addMethodToClass(
if (isAugmentingMethod(customMethod) && !isOverload(customMethod.getStructure())) {
const regex = new RegExp(`this\\.${AUGMENT_CLASS_TOKEN}\\.`, "g");
const modifiedMethodContent = customMethod.getBodyText()?.replace(regex, `this._`);
modifiedMethodContent && customMethod.setBodyText(modifiedMethodContent);
if (modifiedMethodContent) {
customMethod.setBodyText(modifiedMethodContent);
}
}

const methodStructure = customMethod.getStructure();
Expand Down
10 changes: 5 additions & 5 deletions common/tools/dev-tool/src/util/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function commitAll(message: string): Promise<void> {
});

command.on("exit", (code) => {
code === 0 ? resolve() : reject("git exited nonzero");
return code === 0 ? resolve() : reject("git exited nonzero");
});
command.on("error", reject);
});
Expand All @@ -70,7 +70,7 @@ export function add(...paths: string[]): Promise<void> {
});

command.on("exit", (code) => {
code === 0 ? resolve() : reject("git exited nonzero");
return code === 0 ? resolve() : reject("git exited nonzero");
});
command.on("error", reject);
});
Expand All @@ -96,7 +96,7 @@ export function getConfig(
let output = "";
command.stdout.on("data", (data) => (output += data.toString()));
command.on("exit", (code) => {
code === 0 ? resolve(output.trim()) : resolve(undefined);
return code === 0 ? resolve(output.trim()) : resolve(undefined);
});
command.on("error", reject);
});
Expand All @@ -110,7 +110,7 @@ export function checkout(name: string, options: { create?: boolean } = {}): Prom
});

command.on("exit", (code) => {
code === 0 ? resolve() : reject("git exited nonzero");
return code === 0 ? resolve() : reject("git exited nonzero");
});
command.on("error", reject);
});
Expand All @@ -123,7 +123,7 @@ export function currentBranch(): Promise<string> {
let output = "";
command.stdout.on("data", (data) => (output += data.toString()));
command.on("exit", (code) => {
code === 0 ? resolve(output.trim()) : reject("git exited nonzero");
return code === 0 ? resolve(output.trim()) : reject("git exited nonzero");
});
command.on("error", reject);
});
Expand Down
2 changes: 1 addition & 1 deletion common/tools/dev-tool/src/util/pwsh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function hasPowerShell(): Promise<boolean> {
resolve(false);
});
cmd.on("exit", (code) => {
code === 0 ? resolve(true) : resolve(false);
return code === 0 ? resolve(true) : resolve(false);
});
});

Expand Down
10 changes: 5 additions & 5 deletions common/tools/eslint-plugin-azure-sdk-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"sdk-type": "utility",
"private": true,
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "~7.16.0",
"@typescript-eslint/parser": "~7.16.0",
"@typescript-eslint/eslint-plugin": "~8.2.0",
"@typescript-eslint/parser": "~8.2.0",
"eslint": "^8.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-n": "^17.10.1",
Expand All @@ -19,13 +19,13 @@
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@eslint/compat": "^1.0.1",
"@eslint/js": "~9.2.0",
"@typescript-eslint/typescript-estree": "~7.16.0",
"@typescript-eslint/typescript-estree": "~8.2.0",
"@types/eslint": "~8.56.10",
"@types/estree": "~1.0.0",
"@typescript-eslint/utils": "~7.16.0",
"@typescript-eslint/utils": "~8.2.0",
"eslint-config-prettier": "^9.0.0",
"glob": "^10.3.10",
"typescript-eslint": "~7.16.0",
"typescript-eslint": "~8.2.0",
"typescript": "~5.5.3",
"tslib": "^2.6.2"
},
Expand Down
16 changes: 8 additions & 8 deletions common/tools/eslint-plugin-azure-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"prettier": "./prettier.json",
"peerDependencies": {
"@eslint/eslintrc": "^3.0.2",
"@typescript-eslint/eslint-plugin": "~7.16.0",
"@typescript-eslint/parser": "~7.16.0",
"@typescript-eslint/eslint-plugin": "~8.2.0",
"@typescript-eslint/parser": "~8.2.0",
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-n": "^17.10.1",
Expand All @@ -75,23 +75,23 @@
"dependencies": {
"@eslint/compat": "^1.0.1",
"@eslint/js": "~9.2.0",
"@typescript-eslint/typescript-estree": "~7.16.0",
"@typescript-eslint/typescript-estree": "~8.2.0",
"@types/eslint": "~8.56.10",
"@types/estree": "~1.0.0",
"eslint-config-prettier": "^9.0.0",
"glob": "^10.3.10",
"typescript-eslint": "~7.16.0",
"typescript-eslint": "~8.2.0",
"typescript": "~5.5.3",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/eslint__js": "8.42.3",
"@types/eslint-config-prettier": "6.11.3",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "~7.16.0",
"@typescript-eslint/utils": "~7.16.0",
"@typescript-eslint/parser": "~7.16.0",
"@typescript-eslint/rule-tester": "~7.16.0",
"@typescript-eslint/eslint-plugin": "~8.2.0",
"@typescript-eslint/utils": "~8.2.0",
"@typescript-eslint/parser": "~8.2.0",
"@typescript-eslint/rule-tester": "~8.2.0",
"@vitest/coverage-istanbul": "^1.4.0",
"cross-env": "^7.0.3",
"eslint": "^8.50.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ export default {
"@typescript-eslint/no-inferrable-types": "off",
// We use empty extends and empty interface for shimming and renaming extensively
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "off",
"no-shadow": "off",
Expand Down Expand Up @@ -183,6 +185,7 @@ export default {
],
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ const tsEslintCustomization: Record<string, SharedConfig.RuleEntry> = {
"@typescript-eslint/no-inferrable-types": "off",
// We use empty extends and empty interface for shimming and renaming extensively
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-shadow": ["error", { ignoreTypeValueShadow: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const markdownConfigs: FlatConfig.ConfigArray = [
],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-require-imports": "off",
},
},
{
Expand All @@ -50,6 +51,7 @@ const markdownConfigs: FlatConfig.ConfigArray = [
...typescriptEslint.configs.disableTypeChecked,
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "require copyright headers in every source file",
recommended: "recommended",
},
messages: {
noCopyrightHeader: "the file does not have a correct copyright header",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "force api-extractor.json to configure types in a consistent way",
recommended: "recommended",
},
messages: {
...VerifierMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default createRule({
docs: {
description:
"require client methods to use standardized verb prefixes and suffixes where possible",
recommended: "recommended",
},
messages: {
bannedPrefix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "require async client methods to accept an AbortSignalLike parameter",
recommended: "recommended",
},
messages: {
MethodShouldAcceptAbortSignal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default createRule({
docs: {
description:
"force tsconfig.json's 'include' value to at least contain 'src/**/*.ts', 'test/**/*.ts', and 'samples-dev/**/*.ts'",
recommended: "recommended",
},
messages: {
...VerifierMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default createRule({
docs: {
description:
"requires TSDoc comments to not include an '@internal' tag if the object is private",
recommended: "recommended",
},
messages: {
PrivateMembersNotInternal: "private class members should not include an @internal tag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ try {
);
});
}
} catch (err: any) {
} catch {
exclude = [];
}

Expand All @@ -56,7 +56,6 @@ export default createRule({
docs: {
description:
"require TSDoc comments to include an '@internal' or '@hidden' tag if the object is not public-facing",
recommended: "recommended",
},
messages: {
InternalShouldBeMarked:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default createRule({
docs: {
description:
"limit thrown errors to ECMAScript built-in error types (TypeError, RangeError, Error)",
recommended: "recommended",
},
messages: {
ThrownLiteral: "statement is throwing a literal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "force there to be only named exports at the top level",
recommended: "recommended",
},
messages: {
NoDefaultExports: "Exports at top level should be named",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default createRule({
docs: {
description:
"require client methods returning an instance of the client to not include the client name in the method name",
recommended: "recommended",
},
messages: {
ClassNameInMethodName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default createRule({
docs: {
description:
"require client method option parameter type names to be suffixed with Options and prefixed with the method name",
recommended: "recommended",
},
messages: {
UnprefixedParameter: "options parameter type is not prefixed with the {{prefixKind}} name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default createRule({
docs: {
description:
"require client methods returning a subclient to have names prefixed suffixed with 'get' and suffixed with 'client'",
recommended: "recommended",
},
messages: {
BadSubclientMethodName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "forbid usage of TypeScript's const enums",
recommended: "recommended",
},
messages: {
noConstEnum: "const enums should not be used",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "forbid usage of window",
recommended: "recommended",
},
messages: {
useSelf: "`window` should not be used, please use `self` instead.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "force package.json's author value to be 'Microsoft Corporation'",
recommended: "recommended",
},
messages: {
...VerifierMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default createRule({
docs: {
description:
"force package.json's bugs.url value to be 'https://github.com/Azure/azure-sdk-for-js/issues'",
recommended: "recommended",
},
messages: { ...VerifierMessages },
schema: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default createRule<Options, VerifierMessageIds>({
type: "suggestion",
docs: {
description: "Check engines field is set to current Node LTS",
recommended: "recommended",
},
messages: {
...VerifierMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default createRule({
type: "suggestion",
docs: {
description: "requires package.json's files value to contain paths to the package contents",
recommended: "recommended",
},
messages: {
...VerifierMessages,
Expand Down
Loading

0 comments on commit 2ce3c5f

Please sign in to comment.