From 9f9dffd7ce9e3c072133f493853d4348a3828009 Mon Sep 17 00:00:00 2001 From: Maxim Hayes Date: Wed, 6 Dec 2023 11:40:30 -0800 Subject: [PATCH] refactor(lint): rename lint plugin and format --- .eslintrc.js | 4 ++-- .prettierignore | 1 + CONTRIBUTING.md | 18 +++++++++--------- package-lock.json | 8 ++++---- package.json | 8 ++++---- .../index.ts | 2 +- .../lib/rules/no-only-in-tests.ts | 17 +++++++++-------- .../package.json | 4 ++-- .../test/rules/no-only-in-tests.test.ts | 10 +++++----- .../test/testUtil.ts | 8 ++++---- .../tsconfig.json | 2 +- 11 files changed, 42 insertions(+), 40 deletions(-) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/index.ts (93%) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/lib/rules/no-only-in-tests.ts (80%) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/package.json (90%) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/test/rules/no-only-in-tests.test.ts (73%) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/test/testUtil.ts (85%) rename plugins/{eslint-plugin-aws-local => eslint-plugin-aws-toolkits}/tsconfig.json (99%) diff --git a/.eslintrc.js b/.eslintrc.js index e0453ebb865..11f3110cf64 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,7 +9,7 @@ module.exports = { node: true, mocha: true, }, - plugins: ['@typescript-eslint', 'header', 'no-null', 'aws-local'], + plugins: ['@typescript-eslint', 'header', 'no-null', 'aws-toolkits'], extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/eslint-recommended', @@ -115,6 +115,6 @@ module.exports = { }, { lineEndings: 'unix' }, ], - 'aws-local/no-only-in-tests': 'error' + 'aws-toolkits/no-only-in-tests': 'error', }, } diff --git a/.prettierignore b/.prettierignore index 4db303baf6e..16f7af38fb6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,3 +9,4 @@ src/testFixtures/** dist/** types/*.d.ts src.gen/** +plugins/*/dist/** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26b3ef6e303..df19b99f291 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -335,6 +335,15 @@ See [docs/cfn-schema-support.md](./docs/cfn-schema-support.md) for how to fix and improve the JSON schema that provides auto-completion and syntax checking of SAM and CloudFormation `template.yaml` files. +### Custom Lint Rules + +The package.json 'devDependencies' includes `eslint-plugin-aws-toolkits`. This is a local eslint plugin where we define custom lint rules. Additional lint rules and tests for lint rules can be added to this plugin: + +1. Define a new rule in `plugins/eslint-plugin-aws-toolkits/lib/rules`. +2. Create a test for your rule in `plugins/eslint-plugin-aws-toolkits/test/rules` and run with `npm run test` in the root directory of `eslint-plugin-aws-toolkits`. +3. Register your rule in `plugins/eslint-plugin-aws-toolkits/index.ts`. +4. Enable your rule in `.eslintrc`. + ### AWS SDK generator When the AWS SDK does not (yet) support a service but you have an API @@ -443,15 +452,6 @@ If you are contribuing visual assets from other open source repos, the source re 1. Add an entry [here](docs/icons.md#third-party) summarizing the new destination location, where the assets were sourced from, and a brief rationale. -### Custom Lint Rules - -The package.json 'devDependencies' includes `eslint-plugin-aws-local`. This is a local eslint plugin where we define custom lint rules. Additional lint rules and tests for lint rules can be added to this plugin: - -1. Define a new rule in `plugins/eslint-plugin-aws-local/lib/rules`. -2. Create a test for your rule in `plugins/eslint-plugin-aws-local/test/rules` and run with `npm run test` in the root directory of `eslint-plugin-aws-local`. -3. Register your rule in `plugins/eslint-plugin-aws-local/index.ts`. -4. Enable your rule in `.eslintrc`. - ## Using new vscode APIs The minimum required vscode version specified in [package.json](https://github.com/aws/aws-toolkit-vscode/blob/07119655109bb06105a3f53bbcd86b812b32cdbe/package.json#L16) diff --git a/package-lock.json b/package-lock.json index f2876fcc7a7..2d9d9b7c5e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -122,7 +122,7 @@ "esbuild-loader": "2.20.0", "eslint": "^8.26.0", "eslint-config-prettier": "8.8", - "eslint-plugin-aws-local": "file:plugins/eslint-plugin-aws-local", + "eslint-plugin-aws-toolkits": "file:plugins/eslint-plugin-aws-toolkits", "eslint-plugin-header": "^3.1.1", "eslint-plugin-no-null": "^1.0.2", "file-loader": "^6.2.0", @@ -11032,8 +11032,8 @@ "eslint": ">=7.0.0" } }, - "node_modules/eslint-plugin-aws-local": { - "resolved": "plugins/eslint-plugin-aws-local", + "node_modules/eslint-plugin-aws-toolkits": { + "resolved": "plugins/eslint-plugin-aws-toolkits", "link": true }, "node_modules/eslint-plugin-header": { @@ -19776,7 +19776,7 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "plugins/eslint-plugin-aws-local": { + "plugins/eslint-plugin-aws-toolkits": { "version": "1.0.0", "dev": true, "license": "Apache-2.0", diff --git a/package.json b/package.json index c72d328207f..6119f37c066 100644 --- a/package.json +++ b/package.json @@ -4245,9 +4245,9 @@ "testInteg": "npm run testCompile && ts-node ./scripts/test/testInteg.ts && npm run report", "lint": "ts-node ./scripts/lint/testLint.ts && npm run format", "lintfix": "eslint -c .eslintrc.js --fix --ext .ts . && npm run formatfix", - "buildCustomLintPlugin": "cd ./plugins/eslint-plugin-aws-local && npm run build", - "format": "prettier --check src", - "formatfix": "prettier --write src", + "buildCustomLintPlugin": "cd ./plugins/eslint-plugin-aws-toolkits && npm run build", + "format": "prettier --check src plugins", + "formatfix": "prettier --write src plugins", "package": "ts-node ./scripts/build/package.ts", "install-plugin": "vsce package -o aws-toolkit-vscode-test.vsix && code --install-extension aws-toolkit-vscode-test.vsix", "generateClients": "npm run build -w @amzn/codewhisperer-streaming && ts-node ./scripts/build/generateServiceClient.ts ", @@ -4312,7 +4312,7 @@ "eslint-config-prettier": "8.8", "eslint-plugin-header": "^3.1.1", "eslint-plugin-no-null": "^1.0.2", - "eslint-plugin-aws-local": "file:plugins/eslint-plugin-aws-local", + "eslint-plugin-aws-toolkits": "file:plugins/eslint-plugin-aws-toolkits", "file-loader": "^6.2.0", "glob": "^7.1.7", "husky": "^7.0.2", diff --git a/plugins/eslint-plugin-aws-local/index.ts b/plugins/eslint-plugin-aws-toolkits/index.ts similarity index 93% rename from plugins/eslint-plugin-aws-local/index.ts rename to plugins/eslint-plugin-aws-toolkits/index.ts index afee18ab54e..f99995f415a 100644 --- a/plugins/eslint-plugin-aws-local/index.ts +++ b/plugins/eslint-plugin-aws-toolkits/index.ts @@ -9,4 +9,4 @@ const rules = { 'no-only-in-tests': NoOnlyInTests, } -export { rules } \ No newline at end of file +export { rules } diff --git a/plugins/eslint-plugin-aws-local/lib/rules/no-only-in-tests.ts b/plugins/eslint-plugin-aws-toolkits/lib/rules/no-only-in-tests.ts similarity index 80% rename from plugins/eslint-plugin-aws-local/lib/rules/no-only-in-tests.ts rename to plugins/eslint-plugin-aws-toolkits/lib/rules/no-only-in-tests.ts index e592732bd0c..9b28c7a7a0b 100644 --- a/plugins/eslint-plugin-aws-local/lib/rules/no-only-in-tests.ts +++ b/plugins/eslint-plugin-aws-toolkits/lib/rules/no-only-in-tests.ts @@ -9,11 +9,12 @@ import { CallExpression, Identifier, MemberExpression } from '@typescript-eslint import { Rule } from 'eslint' function isValidExpression(node: CallExpression): MemberExpression | undefined { - const isValid = node.callee.type === AST_NODE_TYPES.MemberExpression - && node.callee.object.type === AST_NODE_TYPES.Identifier - && node.callee.property.type === AST_NODE_TYPES.Identifier + const isValid = + node.callee.type === AST_NODE_TYPES.MemberExpression && + node.callee.object.type === AST_NODE_TYPES.Identifier && + node.callee.property.type === AST_NODE_TYPES.Identifier - return isValid ? node.callee as MemberExpression : undefined + return isValid ? (node.callee as MemberExpression) : undefined } export const describeOnlyErrMsg = 'mocha test `.only()` not allowed for `describe`' @@ -22,7 +23,7 @@ export const itOnlyErrMsg = 'mocha test `.only()` not allowed for `it`' export default ESLintUtils.RuleCreator.withoutDocs({ meta: { docs: { - description: 'disallow mocha\'s only() from being published in test code', + description: "disallow mocha's only() from being published in test code", recommended: 'error', }, messages: { @@ -30,7 +31,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({ itOnlyErrMsg, }, type: 'problem', - fixable: "code", + fixable: 'code', schema: [], }, defaultOptions: [], @@ -52,10 +53,10 @@ export default ESLintUtils.RuleCreator.withoutDocs({ return context.report({ node: node.callee, messageId: `${object.name}OnlyErrMsg`, - fix: (fixer) => { + fix: fixer => { // Range - 1 removes the period in `it.only()` return fixer.removeRange([property.range[0] - 1, property.range[1]]) - } + }, }) } }, diff --git a/plugins/eslint-plugin-aws-local/package.json b/plugins/eslint-plugin-aws-toolkits/package.json similarity index 90% rename from plugins/eslint-plugin-aws-local/package.json rename to plugins/eslint-plugin-aws-toolkits/package.json index bea1f089d76..c0ac41916a9 100644 --- a/plugins/eslint-plugin-aws-local/package.json +++ b/plugins/eslint-plugin-aws-toolkits/package.json @@ -1,5 +1,5 @@ { - "name": "eslint-plugin-aws-local", + "name": "eslint-plugin-aws-toolkits", "version": "1.0.0", "description": "Local custom lint rules for AWS Toolkit VSCode", "main": "dist/index.js", @@ -16,4 +16,4 @@ "npm": "^10.1.0" }, "license": "Apache-2.0" -} \ No newline at end of file +} diff --git a/plugins/eslint-plugin-aws-local/test/rules/no-only-in-tests.test.ts b/plugins/eslint-plugin-aws-toolkits/test/rules/no-only-in-tests.test.ts similarity index 73% rename from plugins/eslint-plugin-aws-local/test/rules/no-only-in-tests.test.ts rename to plugins/eslint-plugin-aws-toolkits/test/rules/no-only-in-tests.test.ts index a3c1aded76a..2e10ae5e2ba 100644 --- a/plugins/eslint-plugin-aws-local/test/rules/no-only-in-tests.test.ts +++ b/plugins/eslint-plugin-aws-toolkits/test/rules/no-only-in-tests.test.ts @@ -16,24 +16,24 @@ getRuleTester().run('no-only-in-tests', rules['no-only-in-tests'], { invalid: [ { - code: "describe.only('mySuite', function () { it('does things', async function () {} ) })", + code: "describe.only('mySuite', function () { it('does things', async function () {} ) })", errors: [describeOnlyErrMsg], output: "describe('mySuite', function () { it('does things', async function () {} ) })", }, { - code: "describe('mySuite', function() { it.only('does things', async function () { console.log('did things') })})", + code: "describe('mySuite', function() { it.only('does things', async function () { console.log('did things') })})", errors: [itOnlyErrMsg], output: "describe('mySuite', function() { it('does things', async function () { console.log('did things') })})", }, { - code: "describe.only('mySuite', function() { it.only('does things', async function () { console.log('did things') })})", + code: "describe.only('mySuite', function() { it.only('does things', async function () { console.log('did things') })})", errors: [describeOnlyErrMsg, itOnlyErrMsg], output: "describe('mySuite', function() { it('does things', async function () { console.log('did things') })})", }, { - code: "it.only('does things', async function () { console.log('did things') })", + code: "it.only('does things', async function () { console.log('did things') })", errors: [itOnlyErrMsg], output: "it('does things', async function () { console.log('did things') })", }, ], -}) \ No newline at end of file +}) diff --git a/plugins/eslint-plugin-aws-local/test/testUtil.ts b/plugins/eslint-plugin-aws-toolkits/test/testUtil.ts similarity index 85% rename from plugins/eslint-plugin-aws-local/test/testUtil.ts rename to plugins/eslint-plugin-aws-toolkits/test/testUtil.ts index 58216cb524f..9f23e505fe9 100644 --- a/plugins/eslint-plugin-aws-local/test/testUtil.ts +++ b/plugins/eslint-plugin-aws-toolkits/test/testUtil.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { RuleTester } from "eslint"; +import { RuleTester } from 'eslint' export function getRuleTester() { return new RuleTester({ @@ -12,7 +12,7 @@ export function getRuleTester() { parserOptions: { project: './tsconfig.json', tsconfigRootDir: __dirname, - ecmaVersion: 2021 + ecmaVersion: 2021, }, - }); -} \ No newline at end of file + }) +} diff --git a/plugins/eslint-plugin-aws-local/tsconfig.json b/plugins/eslint-plugin-aws-toolkits/tsconfig.json similarity index 99% rename from plugins/eslint-plugin-aws-local/tsconfig.json rename to plugins/eslint-plugin-aws-toolkits/tsconfig.json index 0fd4d8bc7f9..a08e2959604 100644 --- a/plugins/eslint-plugin-aws-local/tsconfig.json +++ b/plugins/eslint-plugin-aws-toolkits/tsconfig.json @@ -14,4 +14,4 @@ "skipLibCheck": true }, "include": ["lib/**/*", "test/**/*", "index.ts"] -} \ No newline at end of file +}