diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 60cdbe7de24..a30bd468d17 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -26,7 +26,7 @@ | [`no-namespace`] | ✅ | [`@typescript-eslint/no-namespace`] | | [`no-non-null-assertion`] | ✅ | [`@typescript-eslint/no-non-null-assertion`] | | [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] | -| [`no-reference`] | ✅ | [`@typescript-eslint/no-triple-slash-reference`] | +| [`no-reference`] | ✅ | [`@typescript-eslint/triple-slash-reference`] | | [`no-unnecessary-type-assertion`] | ✅ | [`@typescript-eslint/no-unnecessary-type-assertion`] | | [`no-var-requires`] | ✅ | [`@typescript-eslint/no-var-requires`] | | [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] | @@ -148,7 +148,7 @@ | [`import-spacing`] | 🔌 | Use [Prettier] | | [`increment-decrement`] | 🌟 | [`no-plusplus`][no-plusplus] | | [`interface-name`] | ✅ | [`@typescript-eslint/interface-name-prefix`] | -| [`interface-over-type-literal`] | ✅ | [`@typescript-eslint/prefer-interface`] | +| [`interface-over-type-literal`] | ✅ | [`@typescript-eslint/consistent-type-definitions`] | | [`jsdoc-format`] | 🌓 | [`valid-jsdoc`][valid-jsdoc] or [`eslint-plugin-jsdoc`][plugin:jsdoc] | | [`match-default-export-name`] | 🛑 | N/A | | [`newline-before-return`] | 🌟 | [`padding-line-between-statements`][padding-line-between-statements] [1] | @@ -577,6 +577,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/await-thenable`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md [`@typescript-eslint/ban-types`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md [`@typescript-eslint/ban-ts-ignore`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-ignore.md +[`@typescript-eslint/consistent-type-definitions`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md [`@typescript-eslint/explicit-member-accessibility`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md [`@typescript-eslint/member-ordering`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md [`@typescript-eslint/no-explicit-any`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md @@ -586,7 +587,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/promise-function-async`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/promise-function-async.md [`@typescript-eslint/no-namespace`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-namespace.md [`@typescript-eslint/no-non-null-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-assertion.md -[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md +[`@typescript-eslint/triple-slash-reference`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/triple-slash-reference.md [`@typescript-eslint/unbound-method`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md [`@typescript-eslint/no-unnecessary-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md [`@typescript-eslint/no-var-requires`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md @@ -608,7 +609,6 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/no-parameter-properties`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-parameter-properties.md [`@typescript-eslint/member-delimiter-style`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md [`@typescript-eslint/prefer-for-of`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-for-of.md -[`@typescript-eslint/prefer-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-interface.md [`@typescript-eslint/no-array-constructor`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md [`@typescript-eslint/prefer-function-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-function-type.md [`@typescript-eslint/prefer-readonly`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly.md diff --git a/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md b/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md deleted file mode 100644 index 409ff6093ca..00000000000 --- a/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md +++ /dev/null @@ -1,43 +0,0 @@ -# Disallow `/// ` comments (no-triple-slash-reference) - -Triple-slash reference directive comments should not be used anymore. Use `import` instead. - -Before TypeScript adopted ES6 Module syntax, -triple-slash reference directives were used to specify dependencies. -Now that we have `import`, triple-slash reference directives are discouraged for specifying dependencies -in favor of `import`. - -A triple-slash reference directive is a comment beginning with three slashes followed by a path to the module being imported: -`/// `. -ES6 Modules handle this now: -`import animal from "./Animal"` - -## DEPRECATED - this rule has been deprecated in favour of [`triple-slash-reference`](./triple-slash-reference.md) - -## Rule Details - -Does not allow the use of `/// ` comments. - -The following patterns are considered warnings: - -```ts -/// -``` - -The following patterns are not warnings: - -```ts -import Animal from 'Animal'; -``` - -## When Not To Use It - -If you use `/// ` style imports. - -## Further Reading - -- TypeScript [Triple-Slash Directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) - -## Compatibility - -- TSLint: [no-reference](http://palantir.github.io/tslint/rules/no-reference/) diff --git a/packages/eslint-plugin/docs/rules/prefer-interface.md b/packages/eslint-plugin/docs/rules/prefer-interface.md deleted file mode 100644 index 8b995e6b06c..00000000000 --- a/packages/eslint-plugin/docs/rules/prefer-interface.md +++ /dev/null @@ -1,36 +0,0 @@ -# Prefer an interface declaration over a type literal (type T = { ... }) (prefer-interface)\ - -Interfaces are generally preferred over type literals because interfaces can be implemented, extended and merged. - -## DEPRECATED - this rule has been deprecated in favour of [`consistent-type-definitions`](./consistent-type-definitions.md) - -## Rule Details - -Examples of **incorrect** code for this rule. - -```ts -type T = { x: number }; -``` - -Examples of **correct** code for this rule. - -```ts -type T = string; -type Foo = string | {}; - -interface T { - x: number; -} -``` - -## Options - -```CJSON -{ - "interface-over-type-literal": "error" -} -``` - -## Compatibility - -- TSLint: [interface-over-type-literal](https://palantir.github.io/tslint/rules/interface-over-type-literal/) diff --git a/packages/eslint-plugin/src/configs/recommended.json b/packages/eslint-plugin/src/configs/recommended.json index d26fd25d01c..0e6d6d9f665 100644 --- a/packages/eslint-plugin/src/configs/recommended.json +++ b/packages/eslint-plugin/src/configs/recommended.json @@ -24,13 +24,11 @@ "@typescript-eslint/no-non-null-assertion": "error", "@typescript-eslint/no-object-literal-type-assertion": "error", "@typescript-eslint/no-parameter-properties": "error", - "@typescript-eslint/no-triple-slash-reference": "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-interface": "error", "@typescript-eslint/prefer-namespace-keyword": "error", "@typescript-eslint/type-annotation-spacing": "error" } diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index 48280664075..4ae1d9b8ea8 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -34,7 +34,6 @@ import noObjectLiteralTypeAssertion from './no-object-literal-type-assertion'; import noParameterProperties from './no-parameter-properties'; import noRequireImports from './no-require-imports'; import noThisAlias from './no-this-alias'; -import noTripleSlashReference from './no-triple-slash-reference'; import noTypeAlias from './no-type-alias'; import noUnnecessaryQualifier from './no-unnecessary-qualifier'; import noUnnecessaryTypeAssertion from './no-unnecessary-type-assertion'; @@ -45,7 +44,6 @@ import noVarRequires from './no-var-requires'; import preferForOf from './prefer-for-of'; import preferFunctionType from './prefer-function-type'; import preferIncludes from './prefer-includes'; -import preferInterface from './prefer-interface'; import preferNamespaceKeyword from './prefer-namespace-keyword'; import preferReadonly from './prefer-readonly'; import preferRegexpExec from './prefer-regexp-exec'; @@ -98,7 +96,6 @@ export default { 'no-parameter-properties': noParameterProperties, 'no-require-imports': noRequireImports, 'no-this-alias': noThisAlias, - 'no-triple-slash-reference': noTripleSlashReference, 'no-type-alias': noTypeAlias, 'no-unnecessary-qualifier': noUnnecessaryQualifier, 'no-unnecessary-type-assertion': noUnnecessaryTypeAssertion, @@ -109,7 +106,6 @@ export default { 'prefer-for-of': preferForOf, 'prefer-function-type': preferFunctionType, 'prefer-includes': preferIncludes, - 'prefer-interface': preferInterface, 'prefer-namespace-keyword': preferNamespaceKeyword, 'prefer-readonly': preferReadonly, 'prefer-regexp-exec': preferRegexpExec, diff --git a/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts b/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts deleted file mode 100644 index 49f16420166..00000000000 --- a/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts +++ /dev/null @@ -1,42 +0,0 @@ -import * as util from '../util'; - -export default util.createRule({ - name: 'no-triple-slash-reference', - meta: { - type: 'suggestion', - docs: { - description: 'Disallow `/// ` comments', - category: 'Best Practices', - recommended: 'error', - }, - schema: [], - deprecated: true, - replacedBy: ['triple-slash-reference'], - messages: { - noTripleSlashReference: 'Do not use a triple slash reference.', - }, - }, - defaultOptions: [], - create(context) { - const referenceRegExp = /^\/\s* { - if (comment.type !== 'Line') { - return; - } - if (referenceRegExp.test(comment.value)) { - context.report({ - node: comment, - messageId: 'noTripleSlashReference', - }); - } - }); - }, - }; - }, -}); diff --git a/packages/eslint-plugin/src/rules/prefer-interface.ts b/packages/eslint-plugin/src/rules/prefer-interface.ts deleted file mode 100644 index 555e9646b2b..00000000000 --- a/packages/eslint-plugin/src/rules/prefer-interface.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; -import * as util from '../util'; - -export default util.createRule({ - name: 'prefer-interface', - meta: { - type: 'suggestion', - docs: { - description: - 'Prefer an interface declaration over a type literal (type T = { ... })', - category: 'Stylistic Issues', - recommended: 'error', - }, - fixable: 'code', - messages: { - interfaceOverType: 'Use an interface instead of a type literal.', - }, - schema: [], - deprecated: true, - replacedBy: ['consistent-type-definitions'], - }, - defaultOptions: [], - create(context) { - const sourceCode = context.getSourceCode(); - - return { - // VariableDeclaration with kind type has only one VariableDeclarator - "TSTypeAliasDeclaration[typeAnnotation.type='TSTypeLiteral']"( - node: TSESTree.TSTypeAliasDeclaration, - ) { - context.report({ - node: node.id, - messageId: 'interfaceOverType', - fix(fixer) { - const typeNode = node.typeParameters || node.id; - const fixes: TSESLint.RuleFix[] = []; - - const firstToken = sourceCode.getFirstToken(node); - if (firstToken) { - fixes.push(fixer.replaceText(firstToken, 'interface')); - fixes.push( - fixer.replaceTextRange( - [typeNode.range[1], node.typeAnnotation.range[0]], - ' ', - ), - ); - } - - const afterToken = sourceCode.getTokenAfter(node.typeAnnotation); - if ( - afterToken && - afterToken.type === 'Punctuator' && - afterToken.value === ';' - ) { - fixes.push(fixer.remove(afterToken)); - } - - return fixes; - }, - }); - }, - }; - }, -}); diff --git a/packages/eslint-plugin/tests/rules/no-triple-slash-reference.test.ts b/packages/eslint-plugin/tests/rules/no-triple-slash-reference.test.ts deleted file mode 100644 index 5bffd663249..00000000000 --- a/packages/eslint-plugin/tests/rules/no-triple-slash-reference.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import rule from '../../src/rules/no-triple-slash-reference'; -import { RuleTester } from '../RuleTester'; - -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', -}); - -ruleTester.run('no-triple-slash-reference', rule, { - valid: [ - `/// `, - `/// `, - `/// `, - '/// Non-reference triple-slash comment', - "// ", - `/* -/// -let a -*/`, - ], - invalid: [ - { - code: '/// ', - errors: [ - { - messageId: 'noTripleSlashReference', - line: 1, - column: 1, - }, - ], - }, - { - code: ` -/// -let a - `, - errors: [ - { - messageId: 'noTripleSlashReference', - line: 2, - column: 1, - }, - ], - }, - ], -}); diff --git a/packages/eslint-plugin/tests/rules/prefer-interface.test.ts b/packages/eslint-plugin/tests/rules/prefer-interface.test.ts deleted file mode 100644 index ea09c3eb91f..00000000000 --- a/packages/eslint-plugin/tests/rules/prefer-interface.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import rule from '../../src/rules/prefer-interface'; -import { RuleTester } from '../RuleTester'; - -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', -}); - -ruleTester.run('interface-over-type-literal', rule, { - valid: [ - `var foo = { };`, - `type U = string;`, - `type V = { x: number; } | { y: string; };`, - ` -type Record = { - [K in T]: U; -} - `, - ], - invalid: [ - { - code: `type T = { x: number; }`, - output: `interface T { x: number; }`, - errors: [ - { - messageId: 'interfaceOverType', - line: 1, - column: 6, - }, - ], - }, - { - code: `type T={ x: number; }`, - output: `interface T { x: number; }`, - errors: [ - { - messageId: 'interfaceOverType', - line: 1, - column: 6, - }, - ], - }, - { - code: `type T= { x: number; }`, - output: `interface T { x: number; }`, - errors: [ - { - messageId: 'interfaceOverType', - line: 1, - column: 6, - }, - ], - }, - { - code: ` -export type W = { - x: T, -}; -`, - output: ` -export interface W { - x: T, -} -`, - errors: [ - { - messageId: 'interfaceOverType', - line: 2, - column: 13, - }, - ], - }, - ], -});