Skip to content

Commit

Permalink
refactor(lint): rename lint plugin and format
Browse files Browse the repository at this point in the history
  • Loading branch information
hayemaxi committed Dec 6, 2023
1 parent cd8965e commit 9f9dffd
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -115,6 +115,6 @@ module.exports = {
},
{ lineEndings: 'unix' },
],
'aws-local/no-only-in-tests': 'error'
'aws-toolkits/no-only-in-tests': 'error',
},
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ src/testFixtures/**
dist/**
types/*.d.ts
src.gen/**
plugins/*/dist/**
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const rules = {
'no-only-in-tests': NoOnlyInTests,
}

export { rules }
export { rules }
Original file line number Diff line number Diff line change
Expand Up @@ -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`'
Expand All @@ -22,15 +23,15 @@ 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: {
describeOnlyErrMsg,
itOnlyErrMsg,
},
type: 'problem',
fixable: "code",
fixable: 'code',
schema: [],
},
defaultOptions: [],
Expand All @@ -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]])
}
},
})
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -16,4 +16,4 @@
"npm": "^10.1.0"
},
"license": "Apache-2.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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') })",
},
],
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { RuleTester } from "eslint";
import { RuleTester } from 'eslint'

export function getRuleTester() {
return new RuleTester({
Expand All @@ -12,7 +12,7 @@ export function getRuleTester() {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 2021
ecmaVersion: 2021,
},
});
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"skipLibCheck": true
},
"include": ["lib/**/*", "test/**/*", "index.ts"]
}
}

0 comments on commit 9f9dffd

Please sign in to comment.