Skip to content
Permalink
Browse files

feat(eslint-plugin)!: change recommended config (#729)

BREAKING CHANGE: recommended config changes are considered breaking
  • Loading branch information...
bradzacher authored and JamesHenry committed Aug 13, 2019
1 parent de6cc1d commit 428567d7cc0985b1da754f092289212df3fe1bda
Showing with 470 additions and 341 deletions.
  1. +7 −18 .eslintrc.js
  2. 0 .prettierrc → .prettierrc.json
  3. +2 −2 packages/eslint-plugin-tslint/src/custom-linter.ts
  4. +19 −19 packages/eslint-plugin/README.md
  5. +2 −2 packages/eslint-plugin/docs/rules/no-inferrable-types.md
  6. +2 −0 packages/eslint-plugin/package.json
  7. +2 −0 packages/eslint-plugin/src/configs/all.json
  8. +2 −6 packages/eslint-plugin/src/configs/base.json
  9. +21 −11 packages/eslint-plugin/src/configs/recommended.json
  10. +4 −3 packages/eslint-plugin/src/rules/array-type.ts
  11. +2 −2 packages/eslint-plugin/src/rules/await-thenable.ts
  12. +1 −1 packages/eslint-plugin/src/rules/ban-ts-ignore.ts
  13. +3 −2 packages/eslint-plugin/src/rules/ban-types.ts
  14. +1 −1 packages/eslint-plugin/src/rules/camelcase.ts
  15. +2 −2 packages/eslint-plugin/src/rules/class-name-casing.ts
  16. +5 −5 packages/eslint-plugin/src/rules/consistent-type-assertions.ts
  17. +3 −2 packages/eslint-plugin/src/rules/consistent-type-definitions.ts
  18. +2 −2 packages/eslint-plugin/src/rules/explicit-function-return-type.ts
  19. +5 −4 packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
  20. +2 −1 packages/eslint-plugin/src/rules/generic-type-naming.ts
  21. +8 −4 packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts
  22. +6 −9 packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts
  23. +2 −1 packages/eslint-plugin/src/rules/indent.ts
  24. +4 −1 packages/eslint-plugin/src/rules/interface-name-prefix.ts
  25. +4 −4 packages/eslint-plugin/src/rules/member-ordering.ts
  26. +4 −4 packages/eslint-plugin/src/rules/no-empty-function.ts
  27. +1 −1 packages/eslint-plugin/src/rules/no-empty-interface.ts
  28. +3 −2 packages/eslint-plugin/src/rules/no-explicit-any.ts
  29. +5 −3 packages/eslint-plugin/src/rules/no-extra-parens.ts
  30. +1 −1 packages/eslint-plugin/src/rules/no-extraneous-class.ts
  31. +1 −1 packages/eslint-plugin/src/rules/no-floating-promises.ts
  32. +2 −2 packages/eslint-plugin/src/rules/no-for-in-array.ts
  33. +11 −5 packages/eslint-plugin/src/rules/no-inferrable-types.ts
  34. +1 −1 packages/eslint-plugin/src/rules/no-magic-numbers.ts
  35. +4 −4 packages/eslint-plugin/src/rules/no-misused-new.ts
  36. +12 −7 packages/eslint-plugin/src/rules/no-misused-promises.ts
  37. +1 −1 packages/eslint-plugin/src/rules/no-namespace.ts
  38. +2 −2 packages/eslint-plugin/src/rules/no-non-null-assertion.ts
  39. +3 −2 packages/eslint-plugin/src/rules/no-parameter-properties.ts
  40. +4 −2 packages/eslint-plugin/src/rules/no-require-imports.ts
  41. +3 −3 packages/eslint-plugin/src/rules/no-this-alias.ts
  42. +3 −2 packages/eslint-plugin/src/rules/no-type-alias.ts
  43. +1 −1 packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts
  44. +2 −2 packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts
  45. +2 −2 packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts
  46. +1 −1 packages/eslint-plugin/src/rules/no-use-before-define.ts
  47. +1 −1 packages/eslint-plugin/src/rules/no-useless-constructor.ts
  48. +1 −1 packages/eslint-plugin/src/rules/no-var-requires.ts
  49. +1 −1 packages/eslint-plugin/src/rules/prefer-for-of.ts
  50. +7 −4 packages/eslint-plugin/src/rules/prefer-function-type.ts
  51. +1 −1 packages/eslint-plugin/src/rules/prefer-includes.ts
  52. +1 −1 packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts
  53. +20 −18 packages/eslint-plugin/src/rules/prefer-readonly.ts
  54. +2 −2 packages/eslint-plugin/src/rules/prefer-regexp-exec.ts
  55. +1 −1 packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts
  56. +8 −4 packages/eslint-plugin/src/rules/promise-function-async.ts
  57. +1 −1 packages/eslint-plugin/src/rules/require-array-sort-compare.ts
  58. +4 −4 packages/eslint-plugin/src/rules/require-await.ts
  59. +1 −1 packages/eslint-plugin/src/rules/restrict-plus-operands.ts
  60. +2 −1 packages/eslint-plugin/src/rules/semi.ts
  61. +5 −5 packages/eslint-plugin/src/rules/triple-slash-reference.ts
  62. +2 −2 packages/eslint-plugin/src/rules/type-annotation-spacing.ts
  63. +12 −10 packages/eslint-plugin/src/rules/typedef.ts
  64. +3 −3 packages/eslint-plugin/src/rules/unbound-method.ts
  65. +11 −10 packages/eslint-plugin/src/rules/unified-signatures.ts
  66. +2 −2 packages/eslint-plugin/src/util/misc.ts
  67. +5 −2 packages/eslint-plugin/src/util/types.ts
  68. +1 −1 packages/eslint-plugin/tests/RuleTester.ts
  69. +2 −1 packages/eslint-plugin/tests/rules/indent/utils.ts
  70. +10 −0 packages/eslint-plugin/tests/rules/no-this-alias.test.ts
  71. +5 −3 packages/eslint-plugin/tests/rules/no-unused-vars.test.ts
  72. +33 −11 packages/eslint-plugin/tools/generate-configs.ts
  73. +2 −2 packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts
  74. +2 −2 packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts
  75. +2 −1 packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts
  76. +1 −1 packages/experimental-utils/src/eslint-utils/RuleCreator.ts
  77. +4 −1 packages/experimental-utils/src/eslint-utils/deepMerge.ts
  78. +9 −9 packages/parser/src/analyze-scope.ts
  79. +5 −2 packages/parser/src/parser.ts
  80. +4 −2 packages/parser/src/scope/scope-manager.ts
  81. +2 −2 packages/parser/src/simple-traverse.ts
  82. +1 −1 packages/parser/tests/lib/basics.ts
  83. +1 −1 packages/parser/tests/lib/jsx.ts
  84. +12 −9 packages/parser/tests/tools/scope-analysis.ts
  85. +9 −8 packages/parser/tests/tools/test-utils.ts
  86. +3 −2 packages/typescript-estree/src/ast-converter.ts
  87. +12 −5 packages/typescript-estree/src/convert.ts
  88. +9 −2 packages/typescript-estree/src/node-utils.ts
  89. +15 −7 packages/typescript-estree/src/parser.ts
  90. +16 −9 packages/typescript-estree/src/tsconfig-parser.ts
  91. +1 −3 packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
  92. +13 −6 packages/typescript-estree/tests/ast-alignment/parse.ts
  93. +5 −5 packages/typescript-estree/tests/ast-alignment/utils.ts
  94. +4 −4 packages/typescript-estree/tests/lib/convert.ts
  95. +2 −5 packages/typescript-estree/tests/lib/jsx.ts
  96. +2 −2 packages/typescript-estree/tests/lib/semanticInfo.ts
  97. +5 −5 packages/typescript-estree/tools/test-utils.ts
  98. +1 −0 tests/integration/utils/jest-snapshot-resolver.js
  99. +2 −2 tools/generate-contributors.ts
  100. +6 −1 yarn.lock
@@ -21,23 +21,12 @@ module.exports = {
// our plugin :D
//

'@typescript-eslint/ban-ts-ignore': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/unbound-method': 'off',

//
// eslint base
@@ -110,12 +99,12 @@ module.exports = {
'import/no-mutable-exports': 'error',
// Prevent importing the default as if it were named
'import/no-named-default': 'error',
// Prohibit named exports // we want everything to be a named export
'import/no-named-export': 'off',
// Prohibit named exports
'import/no-named-export': 'off', // we want everything to be a named export
// Forbid a module from importing itself
'import/no-self-import': 'error',
// Require modules with a single export to use a default export // we want everything to be named
'import/prefer-default-export': 'off',
// Require modules with a single export to use a default export
'import/prefer-default-export': 'off', // we want everything to be named
},
parserOptions: {
sourceType: 'module',
File renamed without changes.
@@ -1,5 +1,5 @@
import { ILinterOptions, Linter, LintResult } from 'tslint';
import { Program } from 'typescript';
import { Program, SourceFile } from 'typescript';

// We need to access the program, but Linter has private program already
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -14,7 +14,7 @@ export class CustomLinter extends TSLintLinter {
return super.getResult();
}

getSourceFile(fileName: string) {
getSourceFile(fileName: string): SourceFile | undefined {
return this.program.getSourceFile(fileName);
}
}

Large diffs are not rendered by default.

@@ -24,8 +24,8 @@ The default options are:

```JSON
{
"ignoreParameters": true,
"ignoreProperties": true,
"ignoreParameters": false,
"ignoreProperties": false,
}
```

@@ -49,8 +49,10 @@
"devDependencies": {
"@types/json-schema": "^7.0.3",
"@types/marked": "^0.6.5",
"@types/prettier": "^1.18.0",
"chalk": "^2.4.2",
"marked": "^0.7.0",
"prettier": "*",
"typescript": "*"
},
"peerDependencies": {
@@ -24,6 +24,7 @@
"@typescript-eslint/member-ordering": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
@@ -62,6 +63,7 @@
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"require-await": "off",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
@@ -1,9 +1,5 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
]
"parserOptions": { "sourceType": "module" },
"plugins": ["@typescript-eslint"]
}
@@ -1,38 +1,48 @@
{
"extends": "./configs/base.json",
"rules": {
"no-var": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/ban-types": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/explicit-member-accessibility": "error",
"indent": "off",
"@typescript-eslint/indent": "error",
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-delimiter-style": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-parameter-properties": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/type-annotation-spacing": "error"
"@typescript-eslint/prefer-regexp-exec": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"require-await": "off",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error"
}
}
@@ -94,7 +94,8 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Requires using either `T[]` or `Array<T>` for arrays',
category: 'Stylistic Issues',
recommended: 'error',
// too opinionated to be recommended
recommended: false,
},
fixable: 'code',
messages: {
@@ -168,7 +169,7 @@ export default util.createRule<Options, MessageIds>({
}

return {
TSArrayType(node: TSESTree.TSArrayType) {
TSArrayType(node): void {
if (
isArrayOption ||
(isArraySimpleOption && isSimpleType(node.elementType))
@@ -241,7 +242,7 @@ export default util.createRule<Options, MessageIds>({
});
},

TSTypeReference(node: TSESTree.TSTypeReference) {
TSTypeReference(node): void {
if (
isGenericOption ||
node.typeName.type !== AST_NODE_TYPES.Identifier
@@ -9,7 +9,7 @@ export default util.createRule({
docs: {
description: 'Disallows awaiting a value that is not a Thenable',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
messages: {
await: 'Unexpected `await` of a non-Promise (non-"Thenable") value.',
@@ -24,7 +24,7 @@ export default util.createRule({
const checker = parserServices.program.getTypeChecker();

return {
AwaitExpression(node) {
AwaitExpression(node): void {
const originalNode = parserServices.esTreeNodeToTSNodeMap.get<
ts.AwaitExpression
>(node);
@@ -7,7 +7,7 @@ export default util.createRule({
docs: {
description: 'Bans “// @ts-ignore” comments from being used',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
schema: [],
messages: {
@@ -25,7 +25,7 @@ function stringifyTypeName(

function getCustomMessage(
bannedType: null | string | { message?: string; fixWith?: string },
) {
): string {
if (bannedType === null) {
return '';
}
@@ -108,7 +108,7 @@ export default util.createRule<Options, MessageIds>({
],
create(context, [{ types: bannedTypes }]) {
return {
TSTypeReference({ typeName }) {
TSTypeReference({ typeName }): void {
const name = stringifyTypeName(typeName, context.getSourceCode());

if (name in bannedTypes) {
@@ -124,6 +124,7 @@ export default util.createRule<Options, MessageIds>({
name: name,
customMessage,
},
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
fix: fixWith ? fixer => fixer.replaceText(typeName, fixWith) : null,
});
}
@@ -90,7 +90,7 @@ export default util.createRule<Options, MessageIds>({
}

return {
Identifier(node) {
Identifier(node): void {
/*
* Leading and trailing underscores are commonly used to flag
* private/protected identifiers, strip them
@@ -64,15 +64,15 @@ export default util.createRule({
| TSESTree.ClassDeclaration
| TSESTree.TSInterfaceDeclaration
| TSESTree.ClassExpression,
) {
): void {
// class expressions (i.e. export default class {}) are OK
if (node.id && !isPascalCase(node.id.name)) {
report(node, node.id);
}
},
"VariableDeclarator[init.type='ClassExpression']"(
node: TSESTree.VariableDeclarator,
) {
): void {
if (
node.id.type === AST_NODE_TYPES.ArrayPattern ||
node.id.type === AST_NODE_TYPES.ObjectPattern
@@ -77,7 +77,7 @@ export default util.createRule<Options, MessageIds>({

function reportIncorrectAssertionType(
node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression,
) {
): void {
const messageId = options.assertionStyle;
context.report({
node,
@@ -89,7 +89,7 @@ export default util.createRule<Options, MessageIds>({
});
}

function checkType(node: TSESTree.TypeNode) {
function checkType(node: TSESTree.TypeNode): boolean {
switch (node.type) {
case AST_NODE_TYPES.TSAnyKeyword:
case AST_NODE_TYPES.TSUnknownKeyword:
@@ -107,7 +107,7 @@ export default util.createRule<Options, MessageIds>({

function checkExpression(
node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression,
) {
): void {
if (
options.assertionStyle === 'never' ||
options.objectLiteralTypeAssertions === 'allow' ||
@@ -137,15 +137,15 @@ export default util.createRule<Options, MessageIds>({
}

return {
TSTypeAssertion(node) {
TSTypeAssertion(node): void {
if (options.assertionStyle !== 'angle-bracket') {
reportIncorrectAssertionType(node);
return;
}

checkExpression(node);
},
TSAsExpression(node) {
TSAsExpression(node): void {
if (options.assertionStyle !== 'as') {
reportIncorrectAssertionType(node);
return;
@@ -9,6 +9,7 @@ export default util.createRule({
description:
'Consistent with type definition either `interface` or `type`',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
messages: {
@@ -29,7 +30,7 @@ export default util.createRule({
return {
"TSTypeAliasDeclaration[typeAnnotation.type='TSTypeLiteral']"(
node: TSESTree.TSTypeAliasDeclaration,
) {
): void {
if (option === 'interface') {
context.report({
node: node.id,
@@ -63,7 +64,7 @@ export default util.createRule({
});
}
},
TSInterfaceDeclaration(node) {
TSInterfaceDeclaration(node): void {
if (option === 'type') {
context.report({
node: node.id,
@@ -47,8 +47,8 @@ export default util.createRule<Options, MessageIds>({
defaultOptions: [
{
allowExpressions: false,
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: false,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
},
],
create(context, [options]) {
@@ -33,8 +33,9 @@ export default util.createRule<Options, MessageIds>({
docs: {
description:
'Require explicit accessibility modifiers on class properties and methods',
category: 'Best Practices',
recommended: 'error',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
messages: {
missingAccessibility:
@@ -82,7 +83,7 @@ export default util.createRule<Options, MessageIds>({
nodeType: string,
node: TSESTree.Node,
nodeName: string,
) {
): void {
context.report({
node: node,
messageId: messageId,
@@ -179,7 +180,7 @@ export default util.createRule<Options, MessageIds>({
*/
function checkParameterPropertyAccessibilityModifier(
node: TSESTree.TSParameterProperty,
) {
): void {
const nodeType = 'parameter property';
// HAS to be an identifier or assignment or TSC will throw
if (

0 comments on commit 428567d

Please sign in to comment.
You can’t perform that action at this time.