config/eslintrc.js (116 lines of code) (raw):
/**
* JavaScript and generic rules:
*
* https://eslint.org/docs/rules/
*
* TypeScript-specific rules (including migrations from TSlint), see here:
*
* https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md
*/
module.exports = {
env: {
jest: true,
node: true
},
plugins: [
'@stylistic',
'@typescript-eslint',
'import',
'license-header',
'jest',
"deprecation"
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: '2018',
sourceType: 'module',
project: './tsconfig.json',
},
extends: [
'plugin:import/typescript',
'plugin:jest/recommended',
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx']
},
'import/resolver': {
node: {},
typescript: {
project: './tsconfig.json'
}
}
},
ignorePatterns: [ '*.js', '*.d.ts', 'node_modules/', '*.generated.ts' ],
overrides: [
{
// File starts with: "#!/usr/bin/env node"
files: ["bin/stage-deadline.ts"],
rules: {
'license-header/header': 'off',
},
},
],
rules: {
// Require use of the `import { foo } from 'bar';` form instead of `import foo = require('bar');`
'@typescript-eslint/no-require-imports': [ 'error' ],
'@stylistic/indent': [ 'error', 2 ],
// Rule to lint white-space between the TyepScript type annotation syntax
// e.g.
// const foo: number; // Good
// const foo :number; // Bad
// const foo:number; // Bad
'@stylistic/type-annotation-spacing': [
// Error level (fail the lint)
'error',
// Rule options
{
// No whitespace before the colon
before: false,
// Must have whitespace after the colon
after: true,
overrides: {
arrow: {
before: true,
after: true,
},
},
},
],
// Style
'quotes': [ 'error', 'single', { avoidEscape: true } ],
'comma-dangle': [ 'error', 'always-multiline' ], // ensures clean diffs, see https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8
// Require all imported dependencies are actually declared in package.json
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [ // Only allow importing devDependencies from:
'**/build-tools/**', // --> Build tools
'**/test/**' // --> Unit tests
],
optionalDependencies: false, // Disallow importing optional dependencies (those shouldn't be in use in the project)
peerDependencies: false // Disallow importing peer dependencies (that aren't also direct dependencies)
}
],
// Require all imported libraries actually resolve (!!required for import/no-extraneous-dependencies to work!!)
'import/no-unresolved': [ 'error' ],
// Require an ordering on all imports -- unfortunately a different ordering than TSLint used to
// enforce, but there are no compatible ESLint rules as far as I can tell :(
'import/order': ['error', {
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
alphabetize: { order: 'asc', caseInsensitive: true },
}],
// Error if an API is deprecated
'import/no-deprecated': ['error'],
// Cannot import from the same module twice
'no-duplicate-imports': ['error'],
// Cannot shadow names
'no-shadow': ['off'],
'@typescript-eslint/no-shadow': ['error'],
// Required spacing in property declarations (copied from TSLint, defaults are good)
'key-spacing': ['error'],
// Require semicolons
'semi': ['error', 'always'],
// Don't unnecessarily quote properties
'quote-props': ['error', 'consistent-as-needed'],
// No multiple empty lines
'no-multiple-empty-lines': ['error'],
// Max line lengths
'max-len': ['error', {
code: 150,
ignoreUrls: true, // Most common reason to disable it
ignoreStrings: true, // These are not fantastic but necessary for error messages
ignoreTemplateLiterals: true,
ignoreComments: true,
ignoreRegExpLiterals: true,
}],
// One of the easiest mistakes to make
'@typescript-eslint/no-floating-promises': ['error'],
// Don't leave log statements littering the premises!
'no-console': ['error'],
// Useless diff results
'no-trailing-spaces': ['error'],
// Must use foo.bar instead of foo['bar'] if possible
'dot-notation': ['error'],
// Must use 'import' statements (disabled because it doesn't add a lot over no-require-imports)
// '@typescript-eslint/no-var-requires': ['error'],
// Are you sure | is not a typo for || ?
'no-bitwise': ['error'],
// Oh ho ho naming. Everyone's favorite topic!
// FIXME: there's no way to do this properly. The proposed tslint replacement
// works very differently, also checking names in object literals, which we use all over the
// place for configs, mockfs, nodeunit tests, etc.
//
// The maintainer does not want to change behavior.
// https://github.com/typescript-eslint/typescript-eslint/issues/1483
//
// There is no good replacement for tslint's name checking, currently. We will have to make do
// with jsii's validation.
/*
'@typescript-eslint/naming-convention': ['error',
// We could maybe be more specific in a number of these but I didn't want to
// spend too much effort. Knock yourself out if you feel like it.
{ selector: 'enumMember', format: ['PascalCase', 'UPPER_CASE'] },
{ selector: 'variableLike', format: ['camelCase', 'UPPER_CASE'], leadingUnderscore: 'allow' },
{ selector: 'typeLike', format: ['PascalCase'], leadingUnderscore: 'allow' },
{ selector: 'memberLike', format: ['camelCase', 'PascalCase', 'UPPER_CASE'], leadingUnderscore: 'allow' },
// FIXME: there's no way to disable name checking in object literals. Maintainer won't have it
// https://github.com/typescript-eslint/typescript-eslint/issues/1483
],
*/
// Member ordering
'@typescript-eslint/member-ordering': ['error', {
default: [
"public-static-field",
"public-static-method",
"protected-static-field",
"protected-static-method",
"private-static-field",
"private-static-method",
"field",
// Constructors
"constructor", // = ["public-constructor", "protected-constructor", "private-constructor"]
// Methods
"method",
]
}],
// Overrides for plugin:jest/recommended
// We can disable this when we migrate from using `import { expect as expectCDK } from '@aws-cdk/assert';`
// to `import '@aws-cdk/assert/jest';`
"jest/expect-expect": "off",
"license-header/header": [ "error", "./license-header.js" ],
// Warn on usage of deprecated APIs like the CDK v1 APIs that will be removed in CDK v2.
'deprecation/deprecation': "warn",
}
}