Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port builtin tslint rules #830

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tiny-plums-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@definitelytyped/eslint-plugin": patch
"@definitelytyped/dtslint": patch
---

Port tslint builtins -> eslint
1 change: 0 additions & 1 deletion packages/dtslint/dt.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./dtslint.json",
"rules": {
"no-redundant-jsdoc": false,
"npm-naming": [true, { "mode": "code" }]
}
}
104 changes: 1 addition & 103 deletions packages/dtslint/dtslint.json
Original file line number Diff line number Diff line change
@@ -1,110 +1,8 @@
{
"extends": "tslint:all",
"rulesDirectory": "./dist/rules",
"rules": {
// Broken in Typescript 5.0 and above:
"unnecessary-bind": false,
"no-unnecessary-initializer": false,
"prefer-for-of": false,
"only-arrow-functions": false,
// Custom rules
"expect": true,
"unified-signatures": true,
"void-return": true,
"npm-naming": true,

"interface-name": [true, "never-prefix"],
"member-access": [true, "no-public"],
"no-unnecessary-callback-wrapper": true,
"no-namespace": [true, "allow-declarations"],
"one-variable-per-declaration": [true, "ignore-for-loop"],
"prefer-template": [true, "allow-single-concat"],

// TODO?
"align": false, // TODO
"arrow-parens": false,
"arrow-return-shorthand": true, // TODO: "multiline"
"linebreak-style": false, // TODO
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
"no-any": false, // TODO
"no-floating-promises": false, // TODO: https://github.com/palantir/tslint/issues/2879
"no-import-side-effect": false,
"no-this-assignment": false,
"no-unbound-method": false, // TODO?
"no-unsafe-any": false, // TODO
"no-restricted-globals": false,
"number-literal-format": false, // TODO
"promise-function-async": false,
"restrict-plus-operands": false, // TODO
"return-undefined": false, // TODO
"switch-final-break": false, // TODO
"prefer-method-signature": false, // TODO?

// Pretty sure we don't want these
"ban-ts-ignore": false, // Provided by ts-eslint
"binary-expression-operand-order": false,
"class-name": false,
"comment-format": false,
"completed-docs": false,
"curly": false,
"cyclomatic-complexity": false,
"deprecation": false,
"file-name-casing": false,
"forin": false,
"indent": false,
"match-default-export-name": false,
"max-classes-per-file": false,
"max-file-line-count": false,
"max-line-length": false,
"member-ordering": false,
"newline-before-return": false,
"newline-per-chained-call": false,
"no-bitwise": false,
"no-consecutive-blank-lines": false,
"no-console": false,
"no-default-export": false,
"no-empty": false,
"no-implicit-dependencies": false, // See https://github.com/palantir/tslint/issues/3364
"no-inferred-empty-object-type": false,
"no-magic-numbers": false,
"no-non-null-assertion": false,
"no-null-keyword": false,
"no-parameter-properties": false,
"no-parameter-reassignment": false,
"no-reference": false, // But see no-bad-reference
"no-require-imports": false,
"no-shadowed-variable": false,
"no-string-literal": false,
"no-submodule-imports": false,
"no-tautology-expression": false,
"no-trailing-whitespace": false,
"no-unused-expression": false,
"no-unused-variable": false,
"no-use-before-declare": false,
"object-literal-key-quotes": false,
"object-literal-sort-keys": false,
"one-line": false,
"ordered-imports": false,
"prefer-function-over-method": false,
"quotemark": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-boolean-expressions": false,
"strict-type-predicates": false,
"switch-default": false,
"trailing-comma": false,
"triple-equals": [true, "allow-null-check"],
"typedef": false,
"typedef-whitespace": false,
"type-literal-delimiter": false,
"variable-name": false,
"whitespace": false,
"increment-decrement": false,
"unnecessary-constructor": false,
"unnecessary-else": false,
"no-angle-bracket-type-assertion": false,
"no-default-import": false,
"callable-types": false
"npm-naming": true
}
}
27 changes: 27 additions & 0 deletions packages/eslint-plugin/src/configs/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,34 @@ export const all: Linter.BaseConfig = {
"ts-check": false,
},
],
// ported from tslint builtin rules
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/ban-types": [
"error",
{
types: { "{}": false },
extendDefaults: true,
},
],
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/triple-slash-reference": ["error", { types: "prefer-import", path: "always" }],
"@typescript-eslint/no-empty-interface": "error",
"no-duplicate-imports": "error",
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
"@typescript-eslint/naming-convention": [
"error",
{
selector: "interface",
format: [],
custom: {
regex: "^I[A-Z]",
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
match: false,
},
},
],
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/consistent-type-definitions": "error",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ types/no-import-default-of-export-equals/bad.d.ts
==== types/no-import-default-of-export-equals/bad.d.ts ====

declare module "a" {
interface I {}
interface I { i: any }
export = I;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ No errors
==== types/no-import-default-of-export-equals/index.d.ts ====

declare module "agood" {
interface I {}
interface I { i: any }
export default I;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
types/no-import-of-dev-dependencies/bad.d.ts
1:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
2:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
4:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
5:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
1:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
2:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
4:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
5:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies

4 problems (4 errors, 0 warnings)
6 problems (6 errors, 0 warnings)

==== types/no-import-of-dev-dependencies/bad.d.ts ====

/// <reference types="devdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~
!!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not triple-slash reference packages in devDependencies.
/// <reference types="otherdevdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
~~~~~~~~~~~
!!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not triple-slash reference packages in devDependencies.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
types/no-import-of-dev-dependencies/index.d.ts
1:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference
4:1 error Declaration file should not use a global import of itself. Use a relative import @definitelytyped/no-self-import

1 problem (1 error, 0 warnings)
2 problems (2 errors, 0 warnings)

==== types/no-import-of-dev-dependencies/index.d.ts ====

/// <reference types="other"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.

import other from "other";
import self from "no-import-of-dev-dependencies";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
No errors
types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts
1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
3:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference

✖ 3 problems (3 errors, 0 warnings)

==== types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts ====

/// <reference types="devdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
/// <reference types="otherdevdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
/// <reference types="other"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.

import other from "other";
import self from "no-import-of-dev-dependencies";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
No errors
types/no-self-import/no-self-import-tests.ts
1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
3:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference

✖ 3 problems (3 errors, 0 warnings)

==== types/no-self-import/no-self-import-tests.ts ====

/// <reference types="devdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
/// <reference types="otherdevdep"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
/// <reference types="other"/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.

import other from "other";
import self from "no-import-of-dev-dependencies";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ types/no-single-declare-module/bad.d.ts
!!! @definitelytyped/no-single-declare-module: File has only 1 ambient module declaration. Move the contents outside the ambient module block, rename the file to match the ambient module name, and remove the block.

// Other global declarations don't affect this. They should go in "declare global".
interface I {}
interface I { i: any }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ types/strict-export-declare-modifiers/bad1.d.ts

==== types/strict-export-declare-modifiers/bad1.d.ts ====

declare interface I {}
declare interface I { i: any }
~~~~~~~
!!! @definitelytyped/strict-export-declare-modifiers: 'declare' keyword is redundant here.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ types/strict-export-declare-modifiers/bad5.d.ts

==== types/strict-export-declare-modifiers/bad5.d.ts ====

interface I {}
interface I { i: any }
~
!!! @definitelytyped/strict-export-declare-modifiers: All declarations in this module are exported automatically. Prefer to explicitly write 'export' for clarity. If you have a good reason not to export this declaration, add 'export {}' to the module to shut off automatic exporting.
export namespace M {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ No errors

==== types/strict-export-declare-modifiers/good5.d.ts ====

interface J {}
interface J { j: any }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module "a" {
interface I {}
interface I { i: any }
export = I;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module "agood" {
interface I {}
interface I { i: any }
export default I;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "foo" {}

// Other global declarations don't affect this. They should go in "declare global".
interface I {}
interface I { i: any }
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare interface I {}
declare interface I { i: any }
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
interface I {}
interface I { i: any }
export namespace M {}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
interface J {}
interface J { j: any }