Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 508bb41

Browse files
authored
chore: tighter linting (typescript-eslint#530)
1 parent 035b066 commit 508bb41

File tree

22 files changed

+333
-108
lines changed

22 files changed

+333
-108
lines changed

.eslintrc.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
module.exports = {
2+
root: true,
3+
plugins: [
4+
'eslint-plugin',
5+
'@typescript-eslint',
6+
'jest',
7+
'import',
8+
'eslint-comments',
9+
],
10+
env: {
11+
es6: true,
12+
node: true,
13+
},
14+
extends: [
15+
'eslint:recommended',
16+
'plugin:@typescript-eslint/eslint-recommended',
17+
'plugin:@typescript-eslint/recommended',
18+
],
19+
rules: {
20+
//
21+
// eslint base
22+
//
23+
24+
'comma-dangle': ['error', 'always-multiline'],
25+
curly: ['error', 'all'],
26+
'no-mixed-operators': 'error',
27+
'no-console': 'error',
28+
'no-process-exit': 'error',
29+
30+
//
31+
// our plugin :D
32+
//
33+
34+
'@typescript-eslint/indent': 'off',
35+
'@typescript-eslint/no-explicit-any': 'off',
36+
'@typescript-eslint/no-non-null-assertion': 'off',
37+
'@typescript-eslint/explicit-function-return-type': 'off',
38+
'@typescript-eslint/explicit-member-accessibility': 'off',
39+
'@typescript-eslint/no-var-requires': 'off',
40+
'@typescript-eslint/no-use-before-define': 'off',
41+
'@typescript-eslint/no-object-literal-type-assertion': 'off',
42+
'@typescript-eslint/no-parameter-properties': 'off',
43+
44+
//
45+
// eslint-plugin-import
46+
//
47+
48+
// disallow non-import statements appearing before import statements
49+
'import/first': 'error',
50+
// Require a newline after the last import/require in a group
51+
'import/newline-after-import': 'error',
52+
// Forbid import of modules using absolute paths
53+
'import/no-absolute-path': 'error',
54+
// disallow AMD require/define
55+
'import/no-amd': 'error',
56+
// forbid default exports
57+
'import/no-default-export': 'error',
58+
// Forbid the use of extraneous packages
59+
'import/no-extraneous-dependencies': [
60+
'error',
61+
{
62+
devDependencies: true,
63+
peerDependencies: true,
64+
optionalDependencies: false,
65+
},
66+
],
67+
// Forbid mutable exports
68+
'import/no-mutable-exports': 'error',
69+
// Prevent importing the default as if it were named
70+
'import/no-named-default': 'error',
71+
// Prohibit named exports // we want everything to be a named export
72+
'import/no-named-export': 'off',
73+
// Forbid a module from importing itself
74+
'import/no-self-import': 'error',
75+
// Require modules with a single export to use a default export // we want everything to be named
76+
'import/prefer-default-export': 'off',
77+
78+
//
79+
// eslint-plugin-eslint-comment
80+
//
81+
82+
// require a eslint-enable comment for every eslint-disable comment
83+
'eslint-comments/disable-enable-pair': [
84+
'error',
85+
{
86+
allowWholeFile: true,
87+
},
88+
],
89+
// disallow a eslint-enable comment for multiple eslint-disable comments
90+
'eslint-comments/no-aggregating-enable': 'error',
91+
// disallow duplicate eslint-disable comments
92+
'eslint-comments/no-duplicate-disable': 'error',
93+
// disallow eslint-disable comments without rule names
94+
'eslint-comments/no-unlimited-disable': 'error',
95+
// disallow unused eslint-disable comments
96+
'eslint-comments/no-unused-disable': 'error',
97+
// disallow unused eslint-enable comments
98+
'eslint-comments/no-unused-enable': 'error',
99+
// disallow ESLint directive-comments
100+
'eslint-comments/no-use': [
101+
'error',
102+
{
103+
allow: [
104+
'eslint-disable',
105+
'eslint-disable-line',
106+
'eslint-disable-next-line',
107+
'eslint-enable',
108+
],
109+
},
110+
],
111+
},
112+
parserOptions: {
113+
sourceType: 'module',
114+
ecmaFeatures: {
115+
jsx: false,
116+
},
117+
project: './tsconfig.base.json',
118+
},
119+
overrides: [
120+
{
121+
files: [
122+
'packages/eslint-plugin-tslint/tests/**/*.ts',
123+
'packages/eslint-plugin/tests/**/*.test.ts',
124+
'packages/parser/tests/**/*.ts',
125+
'packages/typescript-estree/tests/**/*.ts',
126+
],
127+
env: {
128+
'jest/globals': true,
129+
},
130+
rules: {
131+
'jest/no-disabled-tests': 'warn',
132+
'jest/no-focused-tests': 'error',
133+
'jest/no-alias-methods': 'error',
134+
'jest/no-identical-title': 'error',
135+
'jest/no-jasmine-globals': 'error',
136+
'jest/no-jest-import': 'error',
137+
'jest/no-test-prefixes': 'error',
138+
'jest/no-test-callback': 'error',
139+
'jest/no-test-return-statement': 'error',
140+
'jest/prefer-to-have-length': 'warn',
141+
'jest/prefer-spy-on': 'error',
142+
'jest/valid-expect': 'error',
143+
},
144+
},
145+
{
146+
files: [
147+
'packages/eslint-plugin/tests/**/*.test.ts',
148+
'packages/eslint-plugin-tslint/tests/**/*.spec.ts',
149+
],
150+
rules: {
151+
'eslint-plugin/no-identical-tests': 'error',
152+
},
153+
},
154+
{
155+
files: [
156+
'packages/eslint-plugin/src/rules/**/*.ts',
157+
'packages/eslint-plugin/src/configs/**/*.ts',
158+
'packages/eslint-plugin-tslint/src/rules/**/*.ts',
159+
],
160+
rules: {
161+
// specifically for rules - default exports makes the tooling easier
162+
'import/no-default-export': 'off',
163+
},
164+
},
165+
{
166+
files: ['**/tools/**/*.ts', '**/tests/**/*.ts'],
167+
rules: {
168+
// allow console logs in tools and tests
169+
'no-console': 'off',
170+
},
171+
},
172+
],
173+
};

.eslintrc.json

Lines changed: 0 additions & 73 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,24 @@
4747
"node": ">=6.14.0"
4848
},
4949
"devDependencies": {
50-
"@babel/code-frame": "7.0.0",
51-
"@babel/parser": "7.3.2",
5250
"@commitlint/cli": "^7.1.2",
5351
"@commitlint/config-conventional": "^7.1.2",
5452
"@commitlint/travis-cli": "^7.1.2",
55-
"@types/babel-code-frame": "^6.20.1",
56-
"@types/glob": "^7.1.1",
5753
"@types/jest": "^24.0.6",
58-
"@types/lodash.isplainobject": "^4.0.4",
59-
"@types/lodash.unescape": "^4.0.4",
6054
"@types/node": "^10.12.2",
61-
"@types/semver": "^5.5.0",
6255
"all-contributors-cli": "^6.0.0",
63-
"babel-code-frame": "^6.26.0",
6456
"cz-conventional-changelog": "2.1.0",
6557
"eslint": "^5.12.1",
58+
"eslint-plugin-eslint-comments": "^3.1.1",
6659
"eslint-plugin-eslint-plugin": "^2.0.1",
60+
"eslint-plugin-import": "^2.17.2",
6761
"eslint-plugin-jest": "^22.2.2",
6862
"glob": "7.1.2",
6963
"husky": "^1.3.1",
7064
"isomorphic-fetch": "^2.2.1",
7165
"jest": "24.3.0",
7266
"lerna": "^3.10.5",
7367
"lint-staged": "8.1.0",
74-
"lodash.isplainobject": "4.0.6",
7568
"prettier": "^1.17.0",
7669
"rimraf": "^2.6.3",
7770
"ts-jest": "^24.0.0",

packages/eslint-plugin-tslint/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
},
3333
"peerDependencies": {
3434
"eslint": "^5.0.0",
35-
"tslint": "^5.0.0"
35+
"tslint": "^5.0.0",
36+
"typescript": "*"
3637
},
3738
"devDependencies": {
3839
"@types/json-schema": "^7.0.3",

packages/eslint-plugin/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
"tsutils": "^3.7.0"
4545
},
4646
"devDependencies": {
47-
"eslint-docs": "^0.2.6"
47+
"@typescript-eslint/parser": "1.9.0",
48+
"eslint-docs": "^0.2.6",
49+
"typescript": "*"
4850
},
4951
"peerDependencies": {
5052
"@typescript-eslint/parser": "1.9.0",

packages/eslint-plugin/src/rules/no-magic-numbers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
AST_NODE_TYPES,
99
} from '@typescript-eslint/experimental-utils';
1010
import baseRule from 'eslint/lib/rules/no-magic-numbers';
11+
import { JSONSchema4 } from 'json-schema'; // eslint-disable-line import/no-extraneous-dependencies
1112
import * as util from '../util';
12-
import { JSONSchema4 } from 'json-schema';
1313

1414
type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
1515
type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;

packages/eslint-plugin/src/rules/prefer-regexp-exec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TSESTree } from '@typescript-eslint/typescript-estree';
2-
import { createRule, getParserServices, getTypeName } from '../util';
1+
import { TSESTree } from '@typescript-eslint/experimental-utils';
32
import { getStaticValue } from 'eslint-utils';
3+
import { createRule, getParserServices, getTypeName } from '../util';
44

55
export default createRule({
66
name: 'prefer-regexp-exec',

packages/eslint-plugin/tools/generate-configs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable no-console */
2-
31
import { TSESLint } from '@typescript-eslint/experimental-utils';
42
import fs from 'fs';
53
import path from 'path';

packages/experimental-utils/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232
"typecheck": "tsc --noEmit"
3333
},
3434
"dependencies": {
35+
"@types/json-schema": "^7.0.3",
3536
"@typescript-eslint/typescript-estree": "1.9.0",
3637
"eslint-scope": "^4.0.0"
3738
},
3839
"peerDependencies": {
39-
"eslint": "*",
40+
"eslint": "*"
41+
},
42+
"devDependencies": {
4043
"typescript": "*"
4144
}
4245
}

packages/experimental-utils/src/ts-eslint/CLIEngine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
1+
/* eslint-disable @typescript-eslint/no-namespace */
22

33
import { CLIEngine as ESLintCLIEngine } from 'eslint';
44
import { Linter } from './Linter';

packages/experimental-utils/src/ts-eslint/Linter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
1+
/* eslint-disable @typescript-eslint/no-namespace */
22

33
import { TSESTree, ParserServices } from '@typescript-eslint/typescript-estree';
44
import { Linter as ESLintLinter } from 'eslint';

packages/experimental-utils/src/ts-eslint/Rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ParserServices, TSESTree } from '@typescript-eslint/typescript-estree';
2-
import { JSONSchema4 } from 'json-schema';
2+
import { JSONSchema4 } from 'json-schema'; // eslint-disable-line import/no-extraneous-dependencies
33
import { AST } from './AST';
44
import { Linter } from './Linter';
55
import { Scope } from './Scope';

packages/experimental-utils/src/ts-eslint/SourceCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
1+
/* eslint-disable @typescript-eslint/no-namespace */
22

33
import { ParserServices, TSESTree } from '@typescript-eslint/typescript-estree';
44
import { SourceCode as ESLintSourceCode } from 'eslint';

packages/parser/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"eslint-visitor-keys": "^1.0.0"
4444
},
4545
"devDependencies": {
46-
"@typescript-eslint/shared-fixtures": "1.9.0"
46+
"@types/glob": "^7.1.1",
47+
"@typescript-eslint/shared-fixtures": "1.9.0",
48+
"glob": "^7.1.4"
4749
}
4850
}

packages/parser/typings/eslint.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare module 'eslint/lib/util/traverser' {
22
import { TSESTree } from '@typescript-eslint/experimental-utils';
3+
34
const traverser: {
45
traverse(
56
node: TSESTree.Node,

0 commit comments

Comments
 (0)