Skip to content

Commit

Permalink
chore: standardize eslint setup (aws#7232)
Browse files Browse the repository at this point in the history
Major changes
- switched global eslint configuration in `cdk-build-tools` to
a javascript config, `eslintrc.yml` → `eslintrc.js`.
- each package now has a `.eslintrc` file that simply
re-exports the global config. This file exists for any package
specific customization.
- `eslint` section in `package.json` has been removed, and
moved into the package local `.eslintrc` file.
- lint only `.ts` files - no longer lints `.js` files, generated or
otherwise.
- `yarn lint` now works! ✅
- new pkglint rule that ensures that `.eslintrc.js` exists, that
the file is ignored in `.npmignore` and excluded in
`.gitignore`.

Motivation
At a high level, reduce cdk-specific magic around eslint as
much as possible.

Specifically, bring all packages in line with standard eslint
setup, that can be invoked by running the standard `eslint`
CLI. Further benefit from any tooling or IDE experience
that relies on a standard, conventional setup for a
typescript package with eslint.

Additionally, remove all eslint specific configuration and
complexity out of `cdk-build-tools`. Any configuration
special to a package is now added to the `.eslintrc.js`
local to that package.
  • Loading branch information
Niranjan Jayakar authored Apr 17, 2020
1 parent fda05c3 commit 4e9c425
Show file tree
Hide file tree
Showing 490 changed files with 1,023 additions and 425 deletions.
47 changes: 43 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ and let us know if it's not up-to-date (even better, submit a PR with your corr
- [Main build scripts](#main-build-scripts)
- [Partial build tools](#partial-build-tools)
- [Useful aliases](#useful-aliases)
- [pkglint](#pkglint)
- [awslint](#awslint)
- [Linters](#linters)
- [cfn2ts](#cfn2ts)
- [scripts/foreach.sh](#scriptsforeachsh)
- [Jetbrains support (WebStorm/IntelliJ)](#jetbrains-support-webstormintellij)
Expand Down Expand Up @@ -262,7 +261,47 @@ alias lt='lr test'
alias lw='lr watch'
```

### pkglint
### Linters

All linters are executed automatically as part of the build script, `yarn build`.

They can also be executed independently of the build script. From the root of a specific package (e.g.
`packages/@aws-cdk/aws-ec2`), run the following command to execute all the linters on that package -

```bash
yarn lint
```

The following linters are used -

- [eslint](#eslint)
- [pkglint](#pkglint)
- [awslint](#awslint)

#### eslint

Historically, the CDK has used tslint for linting its typescript source code. With [tslint's deprecation in
2019](https://medium.com/palantir/tslint-in-2019-1a144c2317a9), we are slowly moving over to using eslint.

All packages in the repo use a standard base configuration found at [eslintrc.js](tools/cdk-build-tools/config/eslintrc.js).
This can be customized for any package by modifying the `.eslintrc` file found at its root.

If you're using the VS Code and would like to see eslint violations on it, install the [eslint
extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

The following additional [VS Code setting](https://code.visualstudio.com/docs/getstarted/settings) is required when the
entire project is opened (not required if only a specific module is opened) -

```json
"eslint.workingDirectories": [
{ "pattern": "./packages/@aws-cdk/*" },
{ "pattern": "./packages/@monocdk-experiment/*" },
{ "pattern": "./packages/*" },
{ "pattern": "./tools/*" },
],
```

#### pkglint

The `pkglint` tool "lints" package.json files across the repo according to [rules.ts](tools/pkglint/lib/rules.ts).

Expand All @@ -279,7 +318,7 @@ You can also do that per package:
$ lr pkglint
```

### awslint
#### awslint

**awslint** is a linter for the AWS Construct Library APIs. It is executed as a
part of the build of all AWS modules in the project and enforces the [AWS
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/alexa-ask/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/alexa-ask/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/alexa-ask/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/app-delivery/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
1 change: 1 addition & 0 deletions packages/@aws-cdk/app-delivery/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tsconfig.json
*.d.ts
*.snk
coverage
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/app-delivery/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ coverage

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
3 changes: 3 additions & 0 deletions packages/@aws-cdk/app-delivery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
},
"stability": "experimental",
"maturity": "experimental",
"nyc": {
"statements": 75
},
"awslint": {
"exclude": [
"docs-public-apis:@aws-cdk/app-delivery.PipelineDeployStackAction.actionProperties",
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/assert/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
1 change: 1 addition & 0 deletions packages/@aws-cdk/assert/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/assert/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/assets/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
node_modules
dist
tsconfig.json
tslint.json

.LAST_BUILD
.nyc_output
Expand All @@ -15,3 +14,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/assets/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-accessanalyzer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-accessanalyzer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-accessanalyzer/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo
tsconfig.json
!.jsii
!.jsii
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-acmpca/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-acmpca/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -15,3 +14,4 @@ coverage
.nycrc
.LAST_PACKAGE
*.snk
!.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-acmpca/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ dist
*.tsbuildinfo

tsconfig.json

.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-amazonmq/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-amazonmq/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json

*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amazonmq/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-amplify/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-amplify/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amplify/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dist
# Include .jsii
!.jsii

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-apigateway/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -14,3 +13,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigateway/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigatewayv2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigatewayv2/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo
tsconfig.json
!.jsii
!.jsii
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appconfig/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-appconfig/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -15,4 +14,5 @@ coverage
.LAST_PACKAGE
*.snk

nyc.config.js
nyc.config.js
!.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appconfig/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ dist
*.tsbuildinfo

tsconfig.json

.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -14,3 +13,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appmesh/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appmesh/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appmesh/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-appmesh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"cdk-build": {
"cloudformation": "AWS::AppMesh"
},
"nyc": {
"statements": 75
},
"keywords": [
"aws",
"cdk",
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appstream/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appstream/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ nyc.config.js
coverage
dist
tsconfig.json
tslint.json
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appstream/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appsync/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appsync/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -14,3 +13,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appsync/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dist

*.tsbuildinfo

tsconfig.json
tsconfig.json
.eslintrc.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-athena/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/eslintrc');
module.exports = baseConfig;
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-athena/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
Expand All @@ -14,3 +13,4 @@ coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
Loading

0 comments on commit 4e9c425

Please sign in to comment.