@definitelytyped/eslint-plugin 0.0.203 → 0.0.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/rules/expect.js +3 -1
- package/dist/rules/expect.js.map +1 -1
- package/package.json +2 -2
- package/src/configs/all.ts +0 -189
- package/src/index.ts +0 -18
- package/src/rules/expect.ts +0 -556
- package/src/rules/export-just-namespace.ts +0 -82
- package/src/rules/index.ts +0 -43
- package/src/rules/no-any-union.ts +0 -33
- package/src/rules/no-bad-reference.ts +0 -199
- package/src/rules/no-const-enum.ts +0 -31
- package/src/rules/no-dead-reference.ts +0 -47
- package/src/rules/no-declare-current-package.ts +0 -45
- package/src/rules/no-import-default-of-export-equals.ts +0 -68
- package/src/rules/no-import-of-dev-dependencies.ts +0 -93
- package/src/rules/no-old-dt-header.ts +0 -40
- package/src/rules/no-relative-import-in-test.ts +0 -72
- package/src/rules/no-self-import.ts +0 -56
- package/src/rules/no-single-declare-module.ts +0 -57
- package/src/rules/no-single-element-tuple-type.ts +0 -30
- package/src/rules/no-unnecessary-generics.ts +0 -119
- package/src/rules/no-useless-files.ts +0 -51
- package/src/rules/npm-naming/types.ts +0 -14
- package/src/rules/npm-naming.ts +0 -211
- package/src/rules/prefer-declare-function.ts +0 -37
- package/src/rules/redundant-undefined.ts +0 -61
- package/src/rules/strict-export-declare-modifiers.ts +0 -195
- package/src/suggestions.ts +0 -75
- package/src/util.ts +0 -138
- package/test/__file_snapshots__/types/expect/expect-tests.ts.lint +0 -79
- package/test/__file_snapshots__/types/expect/index.d.ts.lint +0 -19
- package/test/__file_snapshots__/types/export-just-namespace/bad1.d.ts.lint +0 -11
- package/test/__file_snapshots__/types/export-just-namespace/bad2.d.ts.lint +0 -11
- package/test/__file_snapshots__/types/export-just-namespace/bad3.d.ts.lint +0 -12
- package/test/__file_snapshots__/types/export-just-namespace/export-just-namespace-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/export-just-namespace/good1.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good2.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good3.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good4.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good5.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good6.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/export-just-namespace/good7.d.ts.lint +0 -7
- package/test/__file_snapshots__/types/export-just-namespace/good8.d.ts.lint +0 -7
- package/test/__file_snapshots__/types/export-just-namespace/good9.d.ts.lint +0 -15
- package/test/__file_snapshots__/types/foo/foo-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/foo/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/foo/v1/foo-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/foo/v1/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-any-union/bad.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-any-union/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-any-union/no-any-union-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-bad-reference/index.d.ts.lint +0 -43
- package/test/__file_snapshots__/types/no-bad-reference/no-bad-reference-tests.ts.lint +0 -14
- package/test/__file_snapshots__/types/no-bad-reference/v0.1/index.d.ts.lint +0 -48
- package/test/__file_snapshots__/types/no-bad-reference/v0.1/no-bad-reference-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-bad-reference/v11/index.d.ts.lint +0 -48
- package/test/__file_snapshots__/types/no-bad-reference/v11/no-bad-reference-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-const-enum/bad.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-const-enum/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-const-enum/no-const-enum-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-dead-reference/bad.d.ts.lint +0 -18
- package/test/__file_snapshots__/types/no-dead-reference/bad2.d.ts.lint +0 -15
- package/test/__file_snapshots__/types/no-dead-reference/bad3.d.ts.lint +0 -17
- package/test/__file_snapshots__/types/no-dead-reference/index.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-dead-reference/no-dead-reference-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-declare-current-package/index.d.ts.lint +0 -13
- package/test/__file_snapshots__/types/no-declare-current-package/no-declare-current-package-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-declare-current-package/test/deep/import.d.ts.lint +0 -13
- package/test/__file_snapshots__/types/no-declare-current-package-other/index.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-declare-current-package-other/no-declare-current-package-other-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-import-default-of-export-equals/bad.d.ts.lint +0 -17
- package/test/__file_snapshots__/types/no-import-default-of-export-equals/index.d.ts.lint +0 -12
- package/test/__file_snapshots__/types/no-import-default-of-export-equals/no-import-default-of-export-equals-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/bad.d.ts.lint +0 -44
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/index.d.ts.lint +0 -25
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts.lint +0 -39
- package/test/__file_snapshots__/types/no-old-dt-header/index.d.ts.lint +0 -23
- package/test/__file_snapshots__/types/no-old-dt-header/index2.d.ts.lint +0 -14
- package/test/__file_snapshots__/types/no-old-dt-header/no-old-dt-header-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-old-dt-header/ok1.ts.lint +0 -11
- package/test/__file_snapshots__/types/no-old-dt-header/ok2.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-old-dt-header/ok3.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-old-dt-header/ok4.d.ts.lint +0 -12
- package/test/__file_snapshots__/types/no-relative-import-in-test/abc.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-relative-import-in-test/bad.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-relative-import-in-test/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test/abc.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test-tests2.ts.lint +0 -7
- package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-relative-references/index.d.ts.lint +0 -51
- package/test/__file_snapshots__/types/no-relative-references/no-relative-references-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-relative-references/other/other.d.ts.lint +0 -31
- package/test/__file_snapshots__/types/no-relative-references/v1/index.d.ts.lint +0 -57
- package/test/__file_snapshots__/types/no-relative-references/v1/no-relative-references-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-relative-references/v1/other/other.d.ts.lint +0 -31
- package/test/__file_snapshots__/types/no-self-import/bad.d.ts.lint +0 -65
- package/test/__file_snapshots__/types/no-self-import/index.d.ts.lint +0 -19
- package/test/__file_snapshots__/types/no-self-import/no-self-import-tests.ts.lint +0 -39
- package/test/__file_snapshots__/types/no-single-declare-module/bad.d.ts.lint +0 -13
- package/test/__file_snapshots__/types/no-single-declare-module/index.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-single-declare-module/index2.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/no-single-declare-module/index3.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-single-declare-module/no-single-declare-module-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-single-element-tuple-type/bad.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-single-element-tuple-type/index.d.ts.lint +0 -9
- package/test/__file_snapshots__/types/no-single-element-tuple-type/no-single-element-tuple-type-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-unnecessary-generics/bad.d.ts.lint +0 -14
- package/test/__file_snapshots__/types/no-unnecessary-generics/index.d.ts.lint +0 -11
- package/test/__file_snapshots__/types/no-unnecessary-generics/no-unnecessary-generics-tests.ts.lint +0 -44
- package/test/__file_snapshots__/types/no-useless-files/bad.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-useless-files/bad2.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-useless-files/bad3.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/no-useless-files/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-useless-files/index2.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-useless-files/index3.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/no-useless-files/no-useless-files-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/other/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/other/other-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/other/v1/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/other/v1/other-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/prefer-declare-function/bad.d.ts.lint +0 -33
- package/test/__file_snapshots__/types/prefer-declare-function/index.d.ts.lint +0 -14
- package/test/__file_snapshots__/types/prefer-declare-function/prefer-declare-function-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/redundant-undefined/bad.d.ts.lint +0 -15
- package/test/__file_snapshots__/types/redundant-undefined/index.d.ts.lint +0 -9
- package/test/__file_snapshots__/types/redundant-undefined/redundant-undefined-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__foo/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/scoped__foo/scoped__foo-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__foo/v1/index.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/scoped__foo/v1/scoped__foo-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__no-declare-current-package/index.d.ts.lint +0 -13
- package/test/__file_snapshots__/types/scoped__no-declare-current-package/no-declare-current-package-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__no-declare-current-package/test/deep/import.d.ts.lint +0 -13
- package/test/__file_snapshots__/types/scoped__no-relative-references/index.d.ts.lint +0 -51
- package/test/__file_snapshots__/types/scoped__no-relative-references/no-relative-references-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__no-relative-references/other/other.d.ts.lint +0 -31
- package/test/__file_snapshots__/types/scoped__no-relative-references/v1/index.d.ts.lint +0 -57
- package/test/__file_snapshots__/types/scoped__no-relative-references/v1/no-relative-references-tests.ts.lint +0 -10
- package/test/__file_snapshots__/types/scoped__no-relative-references/v1/other/other.d.ts.lint +0 -31
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad1.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad2.d.ts.lint +0 -12
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad3.d.ts.lint +0 -10
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad4.d.ts.lint +0 -12
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad5.d.ts.lint +0 -11
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad6.d.ts.lint +0 -14
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/bad7.d.ts.lint +0 -14
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good1.ts.lint +0 -5
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good2.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good3.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good4.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good5.d.ts.lint +0 -5
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good6.ts.lint +0 -7
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good7.d.ts.lint +0 -6
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good8.d.ts.lint +0 -9
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/good9.d.ts.lint +0 -7
- package/test/__file_snapshots__/types/strict-export-declare-modifiers/strict-export-declare-modifiers-tests.ts.lint +0 -10
- package/test/__snapshots__/plugin.test.ts.snap +0 -262
- package/test/eslint.test.ts +0 -134
- package/test/fixtures/.eslintrc.cjs +0 -4
- package/test/fixtures/notNeededPackages.json +0 -3
- package/test/fixtures/package.json +0 -4
- package/test/fixtures/types/expect/expect-tests.ts +0 -49
- package/test/fixtures/types/expect/index.d.ts +0 -9
- package/test/fixtures/types/expect/package.json +0 -5
- package/test/fixtures/types/expect/tsconfig.json +0 -20
- package/test/fixtures/types/export-just-namespace/bad1.d.ts +0 -2
- package/test/fixtures/types/export-just-namespace/bad2.d.ts +0 -2
- package/test/fixtures/types/export-just-namespace/bad3.d.ts +0 -3
- package/test/fixtures/types/export-just-namespace/export-just-namespace-tests.ts +0 -0
- package/test/fixtures/types/export-just-namespace/good1.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good2.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good3.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good4.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good5.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good6.d.ts +0 -1
- package/test/fixtures/types/export-just-namespace/good7.d.ts +0 -3
- package/test/fixtures/types/export-just-namespace/good8.d.ts +0 -3
- package/test/fixtures/types/export-just-namespace/good9.d.ts +0 -3
- package/test/fixtures/types/export-just-namespace/package.json +0 -8
- package/test/fixtures/types/export-just-namespace/tsconfig.json +0 -31
- package/test/fixtures/types/foo/foo-tests.ts +0 -0
- package/test/fixtures/types/foo/index.d.ts +0 -1
- package/test/fixtures/types/foo/package.json +0 -5
- package/test/fixtures/types/foo/tsconfig.json +0 -20
- package/test/fixtures/types/foo/v1/foo-tests.ts +0 -0
- package/test/fixtures/types/foo/v1/index.d.ts +0 -1
- package/test/fixtures/types/foo/v1/package.json +0 -5
- package/test/fixtures/types/foo/v1/tsconfig.json +0 -20
- package/test/fixtures/types/no-any-union/bad.d.ts +0 -1
- package/test/fixtures/types/no-any-union/index.d.ts +0 -1
- package/test/fixtures/types/no-any-union/no-any-union-tests.ts +0 -1
- package/test/fixtures/types/no-any-union/package.json +0 -8
- package/test/fixtures/types/no-any-union/tsconfig.json +0 -21
- package/test/fixtures/types/no-bad-reference/index.d.ts +0 -16
- package/test/fixtures/types/no-bad-reference/no-bad-reference-tests.ts +0 -2
- package/test/fixtures/types/no-bad-reference/package.json +0 -5
- package/test/fixtures/types/no-bad-reference/tsconfig.json +0 -20
- package/test/fixtures/types/no-bad-reference/v0.1/index.d.ts +0 -15
- package/test/fixtures/types/no-bad-reference/v0.1/no-bad-reference-tests.ts +0 -0
- package/test/fixtures/types/no-bad-reference/v0.1/package.json +0 -5
- package/test/fixtures/types/no-bad-reference/v0.1/tsconfig.json +0 -20
- package/test/fixtures/types/no-bad-reference/v11/index.d.ts +0 -15
- package/test/fixtures/types/no-bad-reference/v11/no-bad-reference-tests.ts +0 -0
- package/test/fixtures/types/no-bad-reference/v11/package.json +0 -5
- package/test/fixtures/types/no-bad-reference/v11/tsconfig.json +0 -20
- package/test/fixtures/types/no-const-enum/bad.d.ts +0 -1
- package/test/fixtures/types/no-const-enum/index.d.ts +0 -1
- package/test/fixtures/types/no-const-enum/no-const-enum-tests.ts +0 -0
- package/test/fixtures/types/no-const-enum/package.json +0 -8
- package/test/fixtures/types/no-const-enum/tsconfig.json +0 -21
- package/test/fixtures/types/no-dead-reference/bad.d.ts +0 -6
- package/test/fixtures/types/no-dead-reference/bad2.d.ts +0 -3
- package/test/fixtures/types/no-dead-reference/bad3.d.ts +0 -5
- package/test/fixtures/types/no-dead-reference/index.d.ts +0 -2
- package/test/fixtures/types/no-dead-reference/no-dead-reference-tests.ts +0 -0
- package/test/fixtures/types/no-dead-reference/package.json +0 -8
- package/test/fixtures/types/no-dead-reference/tsconfig.json +0 -23
- package/test/fixtures/types/no-declare-current-package/index.d.ts +0 -1
- package/test/fixtures/types/no-declare-current-package/no-declare-current-package-tests.ts +0 -0
- package/test/fixtures/types/no-declare-current-package/package.json +0 -8
- package/test/fixtures/types/no-declare-current-package/test/deep/import.d.ts +0 -1
- package/test/fixtures/types/no-declare-current-package/tsconfig.json +0 -21
- package/test/fixtures/types/no-declare-current-package-other/index.d.ts +0 -2
- package/test/fixtures/types/no-declare-current-package-other/no-declare-current-package-other-tests.ts +0 -0
- package/test/fixtures/types/no-declare-current-package-other/package.json +0 -8
- package/test/fixtures/types/no-declare-current-package-other/tsconfig.json +0 -20
- package/test/fixtures/types/no-import-default-of-export-equals/bad.d.ts +0 -8
- package/test/fixtures/types/no-import-default-of-export-equals/index.d.ts +0 -8
- package/test/fixtures/types/no-import-default-of-export-equals/no-import-default-of-export-equals-tests.ts +0 -0
- package/test/fixtures/types/no-import-default-of-export-equals/package.json +0 -8
- package/test/fixtures/types/no-import-default-of-export-equals/tsconfig.json +0 -21
- package/test/fixtures/types/no-import-of-dev-dependencies/bad.d.ts +0 -8
- package/test/fixtures/types/no-import-of-dev-dependencies/index.d.ts +0 -7
- package/test/fixtures/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts +0 -15
- package/test/fixtures/types/no-import-of-dev-dependencies/package.json +0 -14
- package/test/fixtures/types/no-import-of-dev-dependencies/tsconfig.json +0 -21
- package/test/fixtures/types/no-old-dt-header/index.d.ts +0 -14
- package/test/fixtures/types/no-old-dt-header/index2.d.ts +0 -2
- package/test/fixtures/types/no-old-dt-header/no-old-dt-header-tests.ts +0 -0
- package/test/fixtures/types/no-old-dt-header/ok1.ts +0 -2
- package/test/fixtures/types/no-old-dt-header/ok2.d.ts +0 -1
- package/test/fixtures/types/no-old-dt-header/ok3.d.ts +0 -1
- package/test/fixtures/types/no-old-dt-header/ok4.d.ts +0 -3
- package/test/fixtures/types/no-old-dt-header/package.json +0 -8
- package/test/fixtures/types/no-old-dt-header/tsconfig.json +0 -25
- package/test/fixtures/types/no-relative-import-in-test/abc.d.ts +0 -2
- package/test/fixtures/types/no-relative-import-in-test/bad.d.ts +0 -0
- package/test/fixtures/types/no-relative-import-in-test/index.d.ts +0 -1
- package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test/abc.d.ts +0 -2
- package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test-tests.ts +0 -1
- package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test-tests2.ts +0 -3
- package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts +0 -1
- package/test/fixtures/types/no-relative-import-in-test/package.json +0 -8
- package/test/fixtures/types/no-relative-import-in-test/tsconfig.json +0 -25
- package/test/fixtures/types/no-relative-references/index.d.ts +0 -12
- package/test/fixtures/types/no-relative-references/no-relative-references-tests.ts +0 -0
- package/test/fixtures/types/no-relative-references/other/other.d.ts +0 -7
- package/test/fixtures/types/no-relative-references/package.json +0 -5
- package/test/fixtures/types/no-relative-references/tsconfig.json +0 -21
- package/test/fixtures/types/no-relative-references/v1/index.d.ts +0 -15
- package/test/fixtures/types/no-relative-references/v1/no-relative-references-tests.ts +0 -0
- package/test/fixtures/types/no-relative-references/v1/other/other.d.ts +0 -7
- package/test/fixtures/types/no-relative-references/v1/package.json +0 -5
- package/test/fixtures/types/no-relative-references/v1/tsconfig.json +0 -21
- package/test/fixtures/types/no-self-import/bad.d.ts +0 -17
- package/test/fixtures/types/no-self-import/index.d.ts +0 -15
- package/test/fixtures/types/no-self-import/no-self-import-tests.ts +0 -15
- package/test/fixtures/types/no-self-import/package.json +0 -11
- package/test/fixtures/types/no-self-import/tsconfig.json +0 -21
- package/test/fixtures/types/no-single-declare-module/bad.d.ts +0 -4
- package/test/fixtures/types/no-single-declare-module/index.d.ts +0 -2
- package/test/fixtures/types/no-single-declare-module/index2.d.ts +0 -2
- package/test/fixtures/types/no-single-declare-module/index3.d.ts +0 -1
- package/test/fixtures/types/no-single-declare-module/no-single-declare-module-tests.ts +0 -0
- package/test/fixtures/types/no-single-declare-module/package.json +0 -8
- package/test/fixtures/types/no-single-declare-module/tsconfig.json +0 -23
- package/test/fixtures/types/no-single-element-tuple-type/bad.d.ts +0 -1
- package/test/fixtures/types/no-single-element-tuple-type/index.d.ts +0 -5
- package/test/fixtures/types/no-single-element-tuple-type/no-single-element-tuple-type-tests.ts +0 -0
- package/test/fixtures/types/no-single-element-tuple-type/package.json +0 -8
- package/test/fixtures/types/no-single-element-tuple-type/tsconfig.json +0 -21
- package/test/fixtures/types/no-unnecessary-generics/bad.d.ts +0 -2
- package/test/fixtures/types/no-unnecessary-generics/index.d.ts +0 -7
- package/test/fixtures/types/no-unnecessary-generics/no-unnecessary-generics-tests.ts +0 -14
- package/test/fixtures/types/no-unnecessary-generics/package.json +0 -8
- package/test/fixtures/types/no-unnecessary-generics/tsconfig.json +0 -21
- package/test/fixtures/types/no-useless-files/bad.d.ts +0 -1
- package/test/fixtures/types/no-useless-files/bad2.d.ts +0 -0
- package/test/fixtures/types/no-useless-files/bad3.d.ts +0 -1
- package/test/fixtures/types/no-useless-files/index.d.ts +0 -1
- package/test/fixtures/types/no-useless-files/index2.d.ts +0 -1
- package/test/fixtures/types/no-useless-files/index3.d.ts +0 -1
- package/test/fixtures/types/no-useless-files/no-useless-files-tests.ts +0 -0
- package/test/fixtures/types/no-useless-files/package.json +0 -8
- package/test/fixtures/types/no-useless-files/tsconfig.json +0 -25
- package/test/fixtures/types/other/index.d.ts +0 -1
- package/test/fixtures/types/other/other-tests.ts +0 -0
- package/test/fixtures/types/other/package.json +0 -5
- package/test/fixtures/types/other/tsconfig.json +0 -20
- package/test/fixtures/types/other/v1/index.d.ts +0 -1
- package/test/fixtures/types/other/v1/other-tests.ts +0 -0
- package/test/fixtures/types/other/v1/package.json +0 -5
- package/test/fixtures/types/other/v1/tsconfig.json +0 -20
- package/test/fixtures/types/prefer-declare-function/bad.d.ts +0 -9
- package/test/fixtures/types/prefer-declare-function/index.d.ts +0 -2
- package/test/fixtures/types/prefer-declare-function/package.json +0 -8
- package/test/fixtures/types/prefer-declare-function/prefer-declare-function-tests.ts +0 -0
- package/test/fixtures/types/prefer-declare-function/tsconfig.json +0 -21
- package/test/fixtures/types/redundant-undefined/bad.d.ts +0 -3
- package/test/fixtures/types/redundant-undefined/index.d.ts +0 -5
- package/test/fixtures/types/redundant-undefined/package.json +0 -8
- package/test/fixtures/types/redundant-undefined/redundant-undefined-tests.ts +0 -1
- package/test/fixtures/types/redundant-undefined/tsconfig.json +0 -21
- package/test/fixtures/types/scoped__foo/index.d.ts +0 -1
- package/test/fixtures/types/scoped__foo/package.json +0 -5
- package/test/fixtures/types/scoped__foo/scoped__foo-tests.ts +0 -0
- package/test/fixtures/types/scoped__foo/tsconfig.json +0 -20
- package/test/fixtures/types/scoped__foo/v1/index.d.ts +0 -1
- package/test/fixtures/types/scoped__foo/v1/package.json +0 -5
- package/test/fixtures/types/scoped__foo/v1/scoped__foo-tests.ts +0 -0
- package/test/fixtures/types/scoped__foo/v1/tsconfig.json +0 -20
- package/test/fixtures/types/scoped__no-declare-current-package/index.d.ts +0 -1
- package/test/fixtures/types/scoped__no-declare-current-package/no-declare-current-package-tests.ts +0 -0
- package/test/fixtures/types/scoped__no-declare-current-package/package.json +0 -8
- package/test/fixtures/types/scoped__no-declare-current-package/test/deep/import.d.ts +0 -1
- package/test/fixtures/types/scoped__no-declare-current-package/tsconfig.json +0 -21
- package/test/fixtures/types/scoped__no-relative-references/index.d.ts +0 -12
- package/test/fixtures/types/scoped__no-relative-references/no-relative-references-tests.ts +0 -0
- package/test/fixtures/types/scoped__no-relative-references/other/other.d.ts +0 -7
- package/test/fixtures/types/scoped__no-relative-references/package.json +0 -5
- package/test/fixtures/types/scoped__no-relative-references/tsconfig.json +0 -21
- package/test/fixtures/types/scoped__no-relative-references/v1/index.d.ts +0 -15
- package/test/fixtures/types/scoped__no-relative-references/v1/no-relative-references-tests.ts +0 -0
- package/test/fixtures/types/scoped__no-relative-references/v1/other/other.d.ts +0 -7
- package/test/fixtures/types/scoped__no-relative-references/v1/package.json +0 -5
- package/test/fixtures/types/scoped__no-relative-references/v1/tsconfig.json +0 -21
- package/test/fixtures/types/strict-export-declare-modifiers/bad1.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/bad2.d.ts +0 -3
- package/test/fixtures/types/strict-export-declare-modifiers/bad3.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/bad4.d.ts +0 -3
- package/test/fixtures/types/strict-export-declare-modifiers/bad5.d.ts +0 -2
- package/test/fixtures/types/strict-export-declare-modifiers/bad6.d.ts +0 -2
- package/test/fixtures/types/strict-export-declare-modifiers/bad7.d.ts +0 -2
- package/test/fixtures/types/strict-export-declare-modifiers/good1.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/good2.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/good3.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/good4.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/good5.d.ts +0 -1
- package/test/fixtures/types/strict-export-declare-modifiers/good6.ts +0 -3
- package/test/fixtures/types/strict-export-declare-modifiers/good7.d.ts +0 -2
- package/test/fixtures/types/strict-export-declare-modifiers/good8.d.ts +0 -5
- package/test/fixtures/types/strict-export-declare-modifiers/good9.d.ts +0 -3
- package/test/fixtures/types/strict-export-declare-modifiers/package.json +0 -8
- package/test/fixtures/types/strict-export-declare-modifiers/strict-export-declare-modifiers-tests.ts +0 -0
- package/test/fixtures/types/strict-export-declare-modifiers/tsconfig.json +0 -35
- package/test/npm-naming.test.ts +0 -57
- package/test/plugin.test.ts +0 -14
- package/test/tsconfig.json +0 -13
- package/test/types/dts-critic/index.d.ts +0 -9
- package/test/types/dts-critic/package.json +0 -17
- package/test/types/wenceslas/index.d.ts +0 -0
- package/test/types/wenceslas/package.json +0 -17
- package/test/util.test.ts +0 -40
- package/test/util.ts +0 -3
- package/tsconfig.json +0 -11
- package/tsconfig.tsbuildinfo +0 -1
package/src/rules/expect.ts
DELETED
|
@@ -1,556 +0,0 @@
|
|
|
1
|
-
import { isDeclarationPath } from "@definitelytyped/utils";
|
|
2
|
-
import { createRule, findTypesPackage, findUp } from "../util";
|
|
3
|
-
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
4
|
-
import type * as ts from "typescript";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import fs from "fs";
|
|
7
|
-
import { ReportDescriptorMessageData } from "@typescript-eslint/utils/ts-eslint";
|
|
8
|
-
|
|
9
|
-
type TSModule = typeof ts;
|
|
10
|
-
const builtinTypeScript = require("typescript") as TSModule;
|
|
11
|
-
|
|
12
|
-
type Options = [
|
|
13
|
-
{
|
|
14
|
-
versionsToTest?: {
|
|
15
|
-
readonly versionName: string;
|
|
16
|
-
readonly path: string;
|
|
17
|
-
}[];
|
|
18
|
-
},
|
|
19
|
-
];
|
|
20
|
-
type MessageIds =
|
|
21
|
-
| "noTsconfig"
|
|
22
|
-
| "twoAssertions"
|
|
23
|
-
| "failure"
|
|
24
|
-
| "diagnostic"
|
|
25
|
-
| "programContents"
|
|
26
|
-
| "noMatch"
|
|
27
|
-
| "needInstall";
|
|
28
|
-
|
|
29
|
-
const rule = createRule<Options, MessageIds>({
|
|
30
|
-
name: "expect",
|
|
31
|
-
meta: {
|
|
32
|
-
type: "problem",
|
|
33
|
-
docs: {
|
|
34
|
-
description: "Asserts types with $ExpectType.",
|
|
35
|
-
},
|
|
36
|
-
messages: {
|
|
37
|
-
noTsconfig: `Could not find a tsconfig.json file.`,
|
|
38
|
-
twoAssertions: "This line has 2 $ExpectType assertions.",
|
|
39
|
-
failure: `TypeScript{{versionNameString}} expected type to be:\n {{expectedType}}\ngot:\n {{actualType}}`,
|
|
40
|
-
diagnostic: `TypeScript{{versionNameString}} {{message}}`,
|
|
41
|
-
programContents:
|
|
42
|
-
`Program source files differ between TypeScript versions. This may be a dtslint bug.\n` +
|
|
43
|
-
`Expected to find a file '{{fileName}}' present in ${builtinTypeScript.versionMajorMinor}, but did not find it in ts@{{versionName}}.`,
|
|
44
|
-
noMatch:
|
|
45
|
-
"Cannot match a node to this assertion. If this is a multiline function call, ensure the assertion is on the line above.",
|
|
46
|
-
needInstall: `A module look-up failed, this often occurs when you need to run \`pnpm install\` on a dependent module before you can lint.
|
|
47
|
-
|
|
48
|
-
Before you debug, first try running:
|
|
49
|
-
|
|
50
|
-
pnpm install -w --filter '...{./types/{{dirPath}}}...'
|
|
51
|
-
|
|
52
|
-
Then re-run.`,
|
|
53
|
-
},
|
|
54
|
-
schema: [
|
|
55
|
-
{
|
|
56
|
-
type: "object",
|
|
57
|
-
properties: {
|
|
58
|
-
versionsToTest: {
|
|
59
|
-
type: "array",
|
|
60
|
-
items: {
|
|
61
|
-
type: "object",
|
|
62
|
-
properties: {
|
|
63
|
-
versionName: { type: "string" },
|
|
64
|
-
path: { type: "string" },
|
|
65
|
-
},
|
|
66
|
-
required: ["versionName", "path"],
|
|
67
|
-
additionalProperties: false,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
additionalProperties: false,
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
defaultOptions: [{}],
|
|
76
|
-
create(context) {
|
|
77
|
-
if (isDeclarationPath(context.filename) || !context.sourceCode.text.includes("$ExpectType")) {
|
|
78
|
-
return {};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const tsconfigPath = findUp(context.filename, (dir) => {
|
|
82
|
-
const tsconfig = path.join(dir, "tsconfig.json");
|
|
83
|
-
return fs.existsSync(tsconfig) ? tsconfig : undefined;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (!tsconfigPath) {
|
|
87
|
-
context.report({
|
|
88
|
-
messageId: "noTsconfig",
|
|
89
|
-
loc: zeroSourceLocation,
|
|
90
|
-
});
|
|
91
|
-
return {};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// TODO: determine TS versions to run based on this package
|
|
95
|
-
const dirPath = path.dirname(tsconfigPath);
|
|
96
|
-
|
|
97
|
-
const parserServices = ESLintUtils.getParserServices(context);
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
101
|
-
Program(node) {
|
|
102
|
-
// Grab the filename as known by TS, just to make sure we get the right normalization.
|
|
103
|
-
const fileName = parserServices.esTreeNodeToTSNodeMap.get(node).fileName;
|
|
104
|
-
const getLocFromIndex = (index: number) => context.sourceCode.getLocFromIndex(index);
|
|
105
|
-
|
|
106
|
-
const toReport = new Map<string, Omit<ReporterInfo, "versionName"> & { versions: Set<string> }>();
|
|
107
|
-
const reporter: Reporter = ({ versionName, messageId, data, loc }) => {
|
|
108
|
-
const key = JSON.stringify({ messageId, data, loc });
|
|
109
|
-
let existing = toReport.get(key);
|
|
110
|
-
if (existing === undefined) {
|
|
111
|
-
toReport.set(key, (existing = { messageId, data, loc, versions: new Set() }));
|
|
112
|
-
}
|
|
113
|
-
existing.versions.add(versionName);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
let versionsToTest = context.options[0]?.versionsToTest;
|
|
117
|
-
if (!versionsToTest?.length) {
|
|
118
|
-
// In the editor, just use the built-in install of TypeScript.
|
|
119
|
-
versionsToTest = [{ versionName: "", path: require.resolve("typescript") }];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
for (const version of versionsToTest) {
|
|
123
|
-
const ts = require(version.path) as TSModule;
|
|
124
|
-
const program = getProgram(tsconfigPath, ts, version.versionName, parserServices.program);
|
|
125
|
-
walk(
|
|
126
|
-
getLocFromIndex,
|
|
127
|
-
reporter,
|
|
128
|
-
fileName,
|
|
129
|
-
program,
|
|
130
|
-
ts,
|
|
131
|
-
version.versionName,
|
|
132
|
-
/*nextHigherVersion*/ undefined,
|
|
133
|
-
dirPath,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (const { messageId, data, loc, versions } of toReport.values()) {
|
|
138
|
-
const versionNames = [...versions].sort().join(", ");
|
|
139
|
-
context.report({
|
|
140
|
-
messageId,
|
|
141
|
-
data: { ...data, versionNameString: versionNames ? `@${versionNames}` : "" },
|
|
142
|
-
loc,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const programCache = new WeakMap<ts.Program, Map<string, ts.Program>>();
|
|
151
|
-
/** Maps a ts.Program to one created with the version specified in `options`. */
|
|
152
|
-
function getProgram(configFile: string, ts: TSModule, versionName: string, lintProgram: ts.Program): ts.Program {
|
|
153
|
-
let versionToProgram = programCache.get(lintProgram);
|
|
154
|
-
if (versionToProgram === undefined) {
|
|
155
|
-
versionToProgram = new Map<string, ts.Program>();
|
|
156
|
-
programCache.set(lintProgram, versionToProgram);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
let newProgram = versionToProgram.get(versionName);
|
|
160
|
-
if (newProgram === undefined) {
|
|
161
|
-
newProgram = createProgram(configFile, ts);
|
|
162
|
-
versionToProgram.set(versionName, newProgram);
|
|
163
|
-
}
|
|
164
|
-
return newProgram;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function createProgram(configFile: string, ts: TSModule): ts.Program {
|
|
168
|
-
const projectDirectory = path.dirname(configFile);
|
|
169
|
-
const { config } = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
170
|
-
const parseConfigHost: ts.ParseConfigHost = {
|
|
171
|
-
fileExists: fs.existsSync,
|
|
172
|
-
readDirectory: ts.sys.readDirectory,
|
|
173
|
-
readFile: (file) => fs.readFileSync(file, "utf8"),
|
|
174
|
-
useCaseSensitiveFileNames: true,
|
|
175
|
-
};
|
|
176
|
-
const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory), {
|
|
177
|
-
noEmit: true,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
if (config.compilerOptions?.module === "node16" && parsed.options.module === undefined) {
|
|
181
|
-
// TypeScript version is too old to handle the "node16" module option,
|
|
182
|
-
// but we can run tests falling back to commonjs/node.
|
|
183
|
-
parsed.options.module = ts.ModuleKind.CommonJS;
|
|
184
|
-
parsed.options.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const host = ts.createCompilerHost(parsed.options, true);
|
|
188
|
-
return ts.createProgram(parsed.fileNames, parsed.options, host);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
interface ReporterInfo {
|
|
192
|
-
versionName: string;
|
|
193
|
-
messageId: MessageIds;
|
|
194
|
-
data?: ReportDescriptorMessageData;
|
|
195
|
-
loc: Readonly<TSESTree.SourceLocation>;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
type Reporter = (info: ReporterInfo) => void;
|
|
199
|
-
|
|
200
|
-
const zeroSourceLocation: Readonly<TSESTree.SourceLocation> = {
|
|
201
|
-
start: { line: 0, column: 0 },
|
|
202
|
-
end: { line: 0, column: 0 },
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
function walk(
|
|
206
|
-
getLocFromIndex: (index: number) => Readonly<TSESTree.Position>,
|
|
207
|
-
report: Reporter,
|
|
208
|
-
fileName: string,
|
|
209
|
-
program: ts.Program,
|
|
210
|
-
ts: TSModule,
|
|
211
|
-
versionName: string,
|
|
212
|
-
nextHigherVersion: string | undefined,
|
|
213
|
-
dirPath: string,
|
|
214
|
-
): void {
|
|
215
|
-
const sourceFile = program.getSourceFile(fileName)!;
|
|
216
|
-
if (!sourceFile) {
|
|
217
|
-
report({
|
|
218
|
-
versionName,
|
|
219
|
-
messageId: "programContents",
|
|
220
|
-
data: { fileName, versionName },
|
|
221
|
-
loc: zeroSourceLocation,
|
|
222
|
-
});
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const checker = program.getTypeChecker();
|
|
227
|
-
|
|
228
|
-
if (versionName) {
|
|
229
|
-
// If we're using the built-in version of TS, then we're in the editor and tsserver will report diagnostics.
|
|
230
|
-
|
|
231
|
-
// Don't care about emit errors.
|
|
232
|
-
const diagnostics = ts.getPreEmitDiagnostics(program, sourceFile);
|
|
233
|
-
for (const diagnostic of diagnostics) {
|
|
234
|
-
addDiagnosticFailure(diagnostic);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const cannotFindDepsDiags = diagnostics
|
|
238
|
-
.filter((d) => !d.file || isExternalDependency(d.file, dirPath, program))
|
|
239
|
-
.find((d) => d.code === 2307 && d.messageText.toString().includes("Cannot find module"));
|
|
240
|
-
if (cannotFindDepsDiags && cannotFindDepsDiags.file) {
|
|
241
|
-
const packageInfo = findTypesPackage(fileName);
|
|
242
|
-
if (!packageInfo) {
|
|
243
|
-
throw new Error("Could not find package info for " + fileName);
|
|
244
|
-
}
|
|
245
|
-
const dtRoot = findUp(packageInfo.dir, (dir) => {
|
|
246
|
-
if (fs.existsSync(path.join(dir, "notNeededPackages.json"))) {
|
|
247
|
-
return dir;
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
});
|
|
251
|
-
if (dtRoot) {
|
|
252
|
-
const dirPath = path.relative(dtRoot, path.dirname(packageInfo.dir));
|
|
253
|
-
report({
|
|
254
|
-
versionName,
|
|
255
|
-
messageId: "needInstall",
|
|
256
|
-
data: { dirPath },
|
|
257
|
-
loc: zeroSourceLocation,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (sourceFile.isDeclarationFile || !sourceFile.text.includes("$ExpectType")) {
|
|
264
|
-
// Normal file.
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const { typeAssertions, duplicates } = parseAssertions(sourceFile);
|
|
269
|
-
|
|
270
|
-
for (const line of duplicates) {
|
|
271
|
-
addFailureAtLine(report, { versionName, messageId: "twoAssertions" }, line);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const { unmetExpectations, unusedAssertions } = getExpectTypeFailures(sourceFile, typeAssertions, checker, ts);
|
|
275
|
-
for (const { node, expected, actual } of unmetExpectations) {
|
|
276
|
-
report({
|
|
277
|
-
versionName,
|
|
278
|
-
messageId: "failure",
|
|
279
|
-
data: {
|
|
280
|
-
expectedType: expected,
|
|
281
|
-
actualType: actual,
|
|
282
|
-
},
|
|
283
|
-
loc: {
|
|
284
|
-
start: getLocFromIndex(node.getStart(sourceFile)),
|
|
285
|
-
end: getLocFromIndex(node.getEnd()),
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
for (const line of unusedAssertions) {
|
|
290
|
-
addFailureAtLine(
|
|
291
|
-
report,
|
|
292
|
-
{
|
|
293
|
-
versionName,
|
|
294
|
-
messageId: "noMatch",
|
|
295
|
-
},
|
|
296
|
-
line - 1,
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function addDiagnosticFailure(diagnostic: ts.Diagnostic): void {
|
|
301
|
-
const intro = getIntro();
|
|
302
|
-
if (diagnostic.file === sourceFile) {
|
|
303
|
-
const msg = `${intro}\n${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
|
|
304
|
-
report({
|
|
305
|
-
versionName,
|
|
306
|
-
messageId: "diagnostic",
|
|
307
|
-
data: { message: msg },
|
|
308
|
-
loc: {
|
|
309
|
-
start: getLocFromIndex(diagnostic.start!),
|
|
310
|
-
end: getLocFromIndex(diagnostic.start! + diagnostic.length!),
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
report({
|
|
315
|
-
versionName,
|
|
316
|
-
messageId: "diagnostic",
|
|
317
|
-
data: { message: `${intro}\n${fileName}${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}` },
|
|
318
|
-
loc: zeroSourceLocation,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function getIntro(): string {
|
|
324
|
-
if (nextHigherVersion === undefined) {
|
|
325
|
-
return `compile error: `;
|
|
326
|
-
} else {
|
|
327
|
-
const msg = `Compile error in typescript@${versionName} but not in typescript@${nextHigherVersion}.\n`;
|
|
328
|
-
const explain =
|
|
329
|
-
nextHigherVersion === "next"
|
|
330
|
-
? "TypeScript@next features not yet supported."
|
|
331
|
-
: `Fix by adding '"minimumTypeScriptVersion": "${nextHigherVersion}"' to package.json.`;
|
|
332
|
-
return msg + explain;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function addFailureAtLine(report: Reporter, info: Omit<ReporterInfo, "loc">, line: number): void {
|
|
337
|
-
const start = sourceFile.getPositionOfLineAndCharacter(line, 0);
|
|
338
|
-
let end = start + sourceFile.text.split("\n")[line].length;
|
|
339
|
-
if (sourceFile.text[end - 1] === "\r") {
|
|
340
|
-
end--;
|
|
341
|
-
}
|
|
342
|
-
report({
|
|
343
|
-
...info,
|
|
344
|
-
loc: {
|
|
345
|
-
start: getLocFromIndex(start),
|
|
346
|
-
end: getLocFromIndex(end),
|
|
347
|
-
},
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// TODO(jakebailey): dedupe these copied frunctions from dtslint
|
|
353
|
-
function normalizePath(file: string) {
|
|
354
|
-
// replaces '\' with '/' and forces all DOS drive letters to be upper-case
|
|
355
|
-
return path
|
|
356
|
-
.normalize(file)
|
|
357
|
-
.replace(/\\/g, "/")
|
|
358
|
-
.replace(/^[a-z](?=:)/, (c) => c.toUpperCase());
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function startsWithDirectory(filePath: string, dirPath: string): boolean {
|
|
362
|
-
const normalFilePath = normalizePath(filePath);
|
|
363
|
-
const normalDirPath = normalizePath(dirPath).replace(/\/$/, "");
|
|
364
|
-
return normalFilePath.startsWith(normalDirPath + "/") || normalFilePath.startsWith(normalDirPath + "\\");
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
function isExternalDependency(file: ts.SourceFile, dirPath: string, program: ts.Program): boolean {
|
|
368
|
-
return !startsWithDirectory(file.fileName, dirPath) || program.isSourceFileFromExternalLibrary(file);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
interface Assertions {
|
|
372
|
-
/** Map from a line number to the expected type at that line. */
|
|
373
|
-
readonly typeAssertions: Map<number, string>;
|
|
374
|
-
/** Lines with more than one assertion (these are errors). */
|
|
375
|
-
readonly duplicates: readonly number[];
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function parseAssertions(sourceFile: ts.SourceFile): Assertions {
|
|
379
|
-
const typeAssertions = new Map<number, string>();
|
|
380
|
-
const duplicates: number[] = [];
|
|
381
|
-
|
|
382
|
-
const { text } = sourceFile;
|
|
383
|
-
const commentRegexp = /\/\/(.*)/g;
|
|
384
|
-
const lineStarts = sourceFile.getLineStarts();
|
|
385
|
-
let curLine = 0;
|
|
386
|
-
|
|
387
|
-
while (true) {
|
|
388
|
-
const commentMatch = commentRegexp.exec(text);
|
|
389
|
-
if (commentMatch === null) {
|
|
390
|
-
break;
|
|
391
|
-
}
|
|
392
|
-
// Match on the contents of that comment so we do nothing in a commented-out assertion,
|
|
393
|
-
// i.e. `// foo; // $ExpectType number`
|
|
394
|
-
if (!commentMatch[1].startsWith(" $ExpectType ")) {
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
const line = getLine(commentMatch.index);
|
|
398
|
-
const expectedType = commentMatch[1].slice(" $ExpectType ".length);
|
|
399
|
-
// Don't bother with the assertion if there are 2 assertions on 1 line. Just fail for the duplicate.
|
|
400
|
-
if (typeAssertions.delete(line)) {
|
|
401
|
-
duplicates.push(line);
|
|
402
|
-
} else {
|
|
403
|
-
typeAssertions.set(line, expectedType);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return { typeAssertions, duplicates };
|
|
408
|
-
|
|
409
|
-
function getLine(pos: number): number {
|
|
410
|
-
// advance curLine to be the line preceding 'pos'
|
|
411
|
-
while (lineStarts[curLine + 1] <= pos) {
|
|
412
|
-
curLine++;
|
|
413
|
-
}
|
|
414
|
-
// If this is the first token on the line, it applies to the next line.
|
|
415
|
-
// Otherwise, it applies to the text to the left of it.
|
|
416
|
-
return isFirstOnLine(text, lineStarts[curLine], pos) ? curLine + 1 : curLine;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function isFirstOnLine(text: string, lineStart: number, pos: number): boolean {
|
|
421
|
-
for (let i = lineStart; i < pos; i++) {
|
|
422
|
-
if (text[i] !== " ") {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
interface ExpectTypeFailures {
|
|
430
|
-
/** Lines with an $ExpectType, but a different type was there. */
|
|
431
|
-
readonly unmetExpectations: readonly { node: ts.Node; expected: string; actual: string }[];
|
|
432
|
-
/** Lines with an $ExpectType, but no node could be found. */
|
|
433
|
-
readonly unusedAssertions: Iterable<number>;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function getExpectTypeFailures(
|
|
437
|
-
sourceFile: ts.SourceFile,
|
|
438
|
-
typeAssertions: Map<number, string>,
|
|
439
|
-
checker: ts.TypeChecker,
|
|
440
|
-
ts: TSModule,
|
|
441
|
-
): ExpectTypeFailures {
|
|
442
|
-
const unmetExpectations: { node: ts.Node; expected: string; actual: string }[] = [];
|
|
443
|
-
// Match assertions to the first node that appears on the line they apply to.
|
|
444
|
-
// `forEachChild` isn't available as a method in older TypeScript versions, so must use `ts.forEachChild` instead.
|
|
445
|
-
ts.forEachChild(sourceFile, function iterate(node) {
|
|
446
|
-
if (node.kind === ts.SyntaxKind.EndOfFileToken) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const line = lineOfPosition(node.getStart(sourceFile), sourceFile);
|
|
451
|
-
const expected = typeAssertions.get(line);
|
|
452
|
-
if (expected !== undefined) {
|
|
453
|
-
// https://github.com/Microsoft/TypeScript/issues/14077
|
|
454
|
-
if (node.kind === ts.SyntaxKind.ExpressionStatement) {
|
|
455
|
-
node = (node as ts.ExpressionStatement).expression;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const type = checker.getTypeAtLocation(getNodeForExpectType(node, ts));
|
|
459
|
-
|
|
460
|
-
const actual = type
|
|
461
|
-
? checker.typeToString(type, /*enclosingDeclaration*/ undefined, ts.TypeFormatFlags.NoTruncation)
|
|
462
|
-
: "";
|
|
463
|
-
|
|
464
|
-
let actualNormalized: string | undefined;
|
|
465
|
-
|
|
466
|
-
const candidates = expected.split(/\s*\|\|\s*/).map((s) => s.trim());
|
|
467
|
-
|
|
468
|
-
if (
|
|
469
|
-
!(
|
|
470
|
-
// Fast path
|
|
471
|
-
(
|
|
472
|
-
candidates.some((s) => s === actual) ||
|
|
473
|
-
candidates.some((s) => {
|
|
474
|
-
actualNormalized ??= normalizedTypeToString(ts, actual);
|
|
475
|
-
const normalized = normalizedTypeToString(ts, s);
|
|
476
|
-
return normalized === actualNormalized;
|
|
477
|
-
})
|
|
478
|
-
)
|
|
479
|
-
)
|
|
480
|
-
) {
|
|
481
|
-
unmetExpectations.push({ node, expected, actual });
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
typeAssertions.delete(line);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
ts.forEachChild(node, iterate);
|
|
488
|
-
});
|
|
489
|
-
return { unmetExpectations, unusedAssertions: typeAssertions.keys() };
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function normalizedTypeToString(ts: TSModule, type: string) {
|
|
493
|
-
const sourceFile = ts.createSourceFile("foo.ts", `declare var x: ${type};`, ts.ScriptTarget.Latest);
|
|
494
|
-
const typeNode = (sourceFile.statements[0] as ts.VariableStatement).declarationList.declarations[0].type!;
|
|
495
|
-
|
|
496
|
-
const printer = ts.createPrinter({});
|
|
497
|
-
function print(node: ts.Node) {
|
|
498
|
-
return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
|
|
499
|
-
}
|
|
500
|
-
// TODO: pass undefined instead once https://github.com/microsoft/TypeScript/pull/52941 is released
|
|
501
|
-
const context = (ts as any).nullTransformationContext;
|
|
502
|
-
|
|
503
|
-
function visit(node: ts.Node) {
|
|
504
|
-
node = ts.visitEachChild(node, visit, context);
|
|
505
|
-
|
|
506
|
-
if (ts.isUnionTypeNode(node)) {
|
|
507
|
-
const types = node.types
|
|
508
|
-
.map((t) => [t, print(t)] as const)
|
|
509
|
-
.sort((a, b) => (a[1] < b[1] ? -1 : 1))
|
|
510
|
-
.map((t) => t[0]);
|
|
511
|
-
return ts.factory.updateUnionTypeNode(node, ts.factory.createNodeArray(types));
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if (
|
|
515
|
-
ts.isTypeOperatorNode(node) &&
|
|
516
|
-
node.operator === ts.SyntaxKind.ReadonlyKeyword &&
|
|
517
|
-
ts.isArrayTypeNode(node.type)
|
|
518
|
-
) {
|
|
519
|
-
// It's possible that this would conflict with a library which defines their own type with this name,
|
|
520
|
-
// but that's unlikely (and was not previously handled in a prior revision of type string normalization).
|
|
521
|
-
return ts.factory.createTypeReferenceNode("ReadonlyArray", [skipTypeParentheses(ts, node.type.elementType)]);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
return node;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const visited = visit(typeNode);
|
|
528
|
-
return print(visited);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function skipTypeParentheses(ts: TSModule, node: ts.TypeNode): ts.TypeNode {
|
|
532
|
-
while (ts.isParenthesizedTypeNode(node)) node = node.type;
|
|
533
|
-
return node;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function getNodeForExpectType(node: ts.Node, ts: TSModule): ts.Node {
|
|
537
|
-
if (node.kind === ts.SyntaxKind.VariableStatement) {
|
|
538
|
-
// ts2.0 doesn't have `isVariableStatement`
|
|
539
|
-
const {
|
|
540
|
-
declarationList: { declarations },
|
|
541
|
-
} = node as ts.VariableStatement;
|
|
542
|
-
if (declarations.length === 1) {
|
|
543
|
-
const { initializer } = declarations[0];
|
|
544
|
-
if (initializer) {
|
|
545
|
-
return initializer;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return node;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
function lineOfPosition(pos: number, sourceFile: ts.SourceFile): number {
|
|
553
|
-
return sourceFile.getLineAndCharacterOfPosition(pos).line;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
export = rule;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";
|
|
2
|
-
import { createRule } from "../util";
|
|
3
|
-
|
|
4
|
-
interface ExportAssignmentWithIdentifier extends TSESTree.TSExportAssignment {
|
|
5
|
-
expression: TSESTree.Identifier;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const rule = createRule({
|
|
9
|
-
name: "export-just-namespace",
|
|
10
|
-
defaultOptions: [],
|
|
11
|
-
meta: {
|
|
12
|
-
type: "problem",
|
|
13
|
-
docs: {
|
|
14
|
-
description:
|
|
15
|
-
"Forbids `export = foo` where `foo` is a namespace and isn't merged with a function/class/type/interface.",
|
|
16
|
-
},
|
|
17
|
-
messages: {
|
|
18
|
-
useTheBody: "Instead of `export =`-ing a namespace, use the body of the namespace as the module body.",
|
|
19
|
-
},
|
|
20
|
-
schema: [],
|
|
21
|
-
},
|
|
22
|
-
create(context) {
|
|
23
|
-
const ast = context.sourceCode.ast;
|
|
24
|
-
|
|
25
|
-
const exportEqualsNode = ast.body.find(isExportEqualsWithIdentifier);
|
|
26
|
-
if (!exportEqualsNode) {
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isJustNamespace(ast.body, exportEqualsNode.expression.name)) {
|
|
31
|
-
context.report({
|
|
32
|
-
messageId: "useTheBody",
|
|
33
|
-
node: exportEqualsNode,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {};
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @returns Where there is a namespace but there are no functions/classes/etc. with the same name.
|
|
43
|
-
*/
|
|
44
|
-
function isJustNamespace(statements: TSESTree.ProgramStatement[], exportEqualsName: string): boolean {
|
|
45
|
-
let anyNamespace = false;
|
|
46
|
-
|
|
47
|
-
for (const statement of statements) {
|
|
48
|
-
switch (statement.type) {
|
|
49
|
-
case AST_NODE_TYPES.TSModuleDeclaration:
|
|
50
|
-
anyNamespace ||= nameMatches(statement.id);
|
|
51
|
-
break;
|
|
52
|
-
case AST_NODE_TYPES.VariableDeclaration:
|
|
53
|
-
if (statement.declarations.some((d) => nameMatches(d.id))) {
|
|
54
|
-
// OK. It's merged with a variable.
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
case AST_NODE_TYPES.ClassDeclaration:
|
|
59
|
-
case AST_NODE_TYPES.FunctionDeclaration:
|
|
60
|
-
case AST_NODE_TYPES.TSDeclareFunction:
|
|
61
|
-
case AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
62
|
-
case AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
63
|
-
if (nameMatches(statement.id)) {
|
|
64
|
-
// OK. It's merged with a function/class/type/interface.
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return anyNamespace;
|
|
72
|
-
|
|
73
|
-
function nameMatches(nameNode: TSESTree.Node | undefined | null): boolean {
|
|
74
|
-
return !!nameNode && nameNode.type === AST_NODE_TYPES.Identifier && nameNode.name === exportEqualsName;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function isExportEqualsWithIdentifier(node: TSESTree.Node): node is ExportAssignmentWithIdentifier {
|
|
79
|
-
return node.type === AST_NODE_TYPES.TSExportAssignment && node.expression.type === AST_NODE_TYPES.Identifier;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export = rule;
|
package/src/rules/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import exportJustNamespace = require("./export-just-namespace");
|
|
2
|
-
import noAnyUnion = require("./no-any-union");
|
|
3
|
-
import noBadReference = require("./no-bad-reference");
|
|
4
|
-
import noConstEnum = require("./no-const-enum");
|
|
5
|
-
import noDeadReference = require("./no-dead-reference");
|
|
6
|
-
import noDeclareCurrentPackage = require("./no-declare-current-package");
|
|
7
|
-
import noImportDefaultOfExportEquals = require("./no-import-default-of-export-equals");
|
|
8
|
-
import noRelativeImportInTest = require("./no-relative-import-in-test");
|
|
9
|
-
import noSelfImport = require("./no-self-import");
|
|
10
|
-
import noSingleElementTupleType = require("./no-single-element-tuple-type");
|
|
11
|
-
import noUnnecessaryGenerics = require("./no-unnecessary-generics");
|
|
12
|
-
import noUselessFiles = require("./no-useless-files");
|
|
13
|
-
import preferDeclareFunction = require("./prefer-declare-function");
|
|
14
|
-
import redundantUndefined = require("./redundant-undefined");
|
|
15
|
-
import strictExportDeclareModifiers = require("./strict-export-declare-modifiers");
|
|
16
|
-
import noSingleDeclareModule = require("./no-single-declare-module");
|
|
17
|
-
import noOldDTHeader = require("./no-old-dt-header");
|
|
18
|
-
import noImportOfDevDependencies = require("./no-import-of-dev-dependencies");
|
|
19
|
-
import npmNaming = require("./npm-naming");
|
|
20
|
-
import expect = require("./expect");
|
|
21
|
-
|
|
22
|
-
export const rules = {
|
|
23
|
-
"export-just-namespace": exportJustNamespace,
|
|
24
|
-
"no-any-union": noAnyUnion,
|
|
25
|
-
"no-bad-reference": noBadReference,
|
|
26
|
-
"no-const-enum": noConstEnum,
|
|
27
|
-
"no-dead-reference": noDeadReference,
|
|
28
|
-
"no-declare-current-package": noDeclareCurrentPackage,
|
|
29
|
-
"no-import-default-of-export-equals": noImportDefaultOfExportEquals,
|
|
30
|
-
"no-relative-import-in-test": noRelativeImportInTest,
|
|
31
|
-
"no-self-import": noSelfImport,
|
|
32
|
-
"no-single-element-tuple-type": noSingleElementTupleType,
|
|
33
|
-
"no-unnecessary-generics": noUnnecessaryGenerics,
|
|
34
|
-
"no-useless-files": noUselessFiles,
|
|
35
|
-
"prefer-declare-function": preferDeclareFunction,
|
|
36
|
-
"redundant-undefined": redundantUndefined,
|
|
37
|
-
"strict-export-declare-modifiers": strictExportDeclareModifiers,
|
|
38
|
-
"no-single-declare-module": noSingleDeclareModule,
|
|
39
|
-
"no-old-dt-header": noOldDTHeader,
|
|
40
|
-
"no-import-of-dev-dependencies": noImportOfDevDependencies,
|
|
41
|
-
"npm-naming": npmNaming,
|
|
42
|
-
expect,
|
|
43
|
-
};
|