Skip to content

Commit c2b4541

Browse files
authored
Review of TypeScript Rules (#18)
1 parent c6bd2da commit c2b4541

16 files changed

+579
-88
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
on:
2-
pull_request_target:
2+
pull_request:
33
push:
44
branches:
55
- '*'
6+
tags:
7+
- 'v*'
68

79
jobs:
810
build:
9-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-18.04
1012
steps:
1113
- uses: actions/checkout@v2
14+
15+
# Install dependencies
1216
- uses: actions/setup-node@v1
1317
with:
1418
node-version: '12'
19+
registry-url: 'https://registry.npmjs.org'
1520
- run: npm ci
21+
22+
# Build
23+
- run: npm pack
24+
- uses: actions/upload-artifact@v2
25+
with:
26+
name: npm package
27+
path: ./ni-eslint-config-*.tgz
28+
if-no-files-found: error
29+
30+
# Test
31+
- run: npm run test-typescript
32+
- run: npm run test-typescript-typed
33+
- run: npm run dev-print-typescript-props
34+
35+
# Publish
36+
- if: startsWith(github.ref, 'refs/tags/v')
37+
run: npm publish
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
33
*.tgz
4+
.vscode

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module.exports = {
2-
extends: 'airbnb-base',
2+
extends: [
3+
/*
4+
airbnb-base source:
5+
https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/index.js
6+
*/
7+
'airbnb-base'
8+
],
39
rules: {
410
/*
511
Omit arrow function parenthesis where they are not required to improve readability.
@@ -57,11 +63,17 @@ module.exports = {
5763
*/
5864
'linebreak-style': 'off',
5965

66+
/*
67+
Requires empty lines between multiline class members but avoids the empty line
68+
for single line members to reduce the amount of vertical space used in a class.
69+
*/
70+
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
71+
6072
/*
6173
Including one class per file is a best practice in general and also recommended by the
6274
Angular style guide. However, migrating older projects may not be trivial, and there
6375
may be exceptions for public/internal types that are only used as part of the interface
64-
to the main type and no other types
76+
to the main type and no other types.
6577
*/
6678
'max-classes-per-file': ['error', 1],
6779

@@ -132,6 +144,9 @@ module.exports = {
132144
'error', {
133145
selector: 'LabeledStatement',
134146
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
147+
}, {
148+
selector: "UnaryExpression[operator='delete']",
149+
message: 'The `delete` operator is not allowed. If using an object keys as a map, use the ES `Map` data structure instead.'
135150
}, {
136151
selector: 'WithStatement',
137152
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
rules: {
3+
// Defined by Airbnb
4+
// 'dot-notation': 'off',
5+
// '@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
6+
7+
// Defined by Airbnb
8+
// 'no-implied-eval': 'off',
9+
// '@typescript-eslint/no-implied-eval': 'error',
10+
11+
// Defined by Airbnb
12+
// 'no-throw-literal': 'off',
13+
// '@typescript-eslint/no-throw-literal': 'error',
14+
15+
// Defined by Airbnb
16+
// 'require-await': 'off',
17+
// '@typescript-eslint/require-await': 'off',
18+
19+
// Defined by Airbnb
20+
// 'no-return-await': 'off',
21+
// '@typescript-eslint/return-await': 'error',
22+
}
23+
};

lib/typescript-extensions.js

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
module.exports = {
2+
rules: {
3+
/*
4+
The following are extension rules that replace core JavaScript rules to support
5+
TypeScript.
6+
* When upgrading, changes to these rules can be identified in the typescript-eslint
7+
changelog under features and breaking changes:
8+
https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#extension-rules
9+
* In addition, the `npm run dev-print-typescript-props` command can be used to list
10+
the expected extension properties.
11+
* The value of the extension properties should match the value chosen by the
12+
JavaScript / Airbnb configuration.
13+
*/
14+
15+
// Defined by Airbnb
16+
'brace-style': 'off',
17+
'@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }],
18+
19+
// Defined by NI
20+
'comma-dangle': 'off',
21+
'@typescript-eslint/comma-dangle': ['error', 'only-multiline'],
22+
23+
// Defined by Airbnb
24+
'comma-spacing': 'off',
25+
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],
26+
27+
// Defined by Airbnb
28+
'default-param-last': 'off',
29+
'@typescript-eslint/default-param-last': 'off',
30+
31+
// Defined by Airbnb
32+
'func-call-spacing': 'off',
33+
'@typescript-eslint/func-call-spacing': ['error', 'never'],
34+
35+
// Defined by NI
36+
indent: 'off',
37+
'@typescript-eslint/indent': ['error', 4],
38+
39+
// Defined by Airbnb
40+
'init-declarations': 'off',
41+
'@typescript-eslint/init-declarations': 'off',
42+
43+
// Defined by Airbnb
44+
'keyword-spacing': 'off',
45+
'@typescript-eslint/keyword-spacing': ['error', {
46+
before: true,
47+
after: true,
48+
overrides: {
49+
return: { after: true },
50+
throw: { after: true },
51+
case: { after: true }
52+
}
53+
}],
54+
55+
// Defined by NI
56+
'lines-between-class-members': 'off',
57+
'@typescript-eslint/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
58+
59+
// Defined by Airbnb
60+
'no-array-constructor': 'off',
61+
'@typescript-eslint/no-array-constructor': 'error',
62+
63+
// Defined by Airbnb
64+
'no-dupe-class-members': 'off',
65+
'@typescript-eslint/no-dupe-class-members': 'error',
66+
67+
// Defined by Airbnb
68+
'no-duplicate-imports': 'off',
69+
'@typescript-eslint/no-duplicate-imports': 'off',
70+
71+
// Defined by Airbnb
72+
'no-empty-function': 'off',
73+
'@typescript-eslint/no-empty-function': ['error', {
74+
allow: [
75+
'arrowFunctions',
76+
'functions',
77+
'methods'
78+
]
79+
}],
80+
81+
// Defined by Airbnb
82+
'no-extra-parens': 'off',
83+
'@typescript-eslint/no-extra-parens': ['off', 'all', {
84+
conditionalAssign: true,
85+
nestedBinaryExpressions: false,
86+
returnAssign: false,
87+
ignoreJSX: 'all',
88+
enforceForArrowConditionals: false,
89+
}],
90+
91+
// Defined by Airbnb
92+
'no-extra-semi': 'off',
93+
'@typescript-eslint/no-extra-semi': 'error',
94+
95+
// Defined by Airbnb
96+
'no-invalid-this': 'off',
97+
'@typescript-eslint/no-invalid-this': 'off',
98+
99+
// Defined by NI
100+
'no-loop-func': 'off',
101+
'@typescript-eslint/no-loop-func': 'error',
102+
103+
// Defined by Airbnb
104+
'no-loss-of-precision': 'off',
105+
'@typescript-eslint/no-loss-of-precision': 'off',
106+
107+
// Defined by Airbnb
108+
'no-magic-numbers': 'off',
109+
'@typescript-eslint/no-magic-numbers': ['off', {
110+
ignore: [],
111+
ignoreArrayIndexes: true,
112+
enforceConst: true,
113+
detectObjects: false,
114+
}],
115+
116+
// Defined by Airbnb
117+
'no-redeclare': 'off',
118+
'@typescript-eslint/no-redeclare': 'error',
119+
120+
// Defined by Airbnb
121+
'no-shadow': 'off',
122+
'@typescript-eslint/no-shadow': 'error',
123+
124+
// Defined by Airbnb
125+
'no-unused-expressions': 'off',
126+
'@typescript-eslint/no-unused-expressions': ['error', {
127+
allowShortCircuit: false,
128+
allowTernary: false,
129+
allowTaggedTemplates: false,
130+
}],
131+
132+
// Defined by Airbnb
133+
'no-unused-vars': 'off',
134+
'@typescript-eslint/no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
135+
136+
// Defined by NI
137+
'no-use-before-define': 'off',
138+
'@typescript-eslint/no-use-before-define': ['error', { functions: false, classes: true, variables: true }],
139+
140+
// Defined by Airbnb
141+
'no-useless-constructor': 'off',
142+
'@typescript-eslint/no-useless-constructor': 'error',
143+
144+
// Available in newer typescript-eslint version, enable on upgrade.
145+
// See: https://github.com/ni/javascript-styleguide/pull/18#discussion_r569795937
146+
// Defined by Airbnb
147+
'object-curly-spacing': 'off',
148+
// '@typescript-eslint/object-curly-spacing': ['error', 'always'],
149+
150+
// Defined by Airbnb
151+
quotes: 'off',
152+
'@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }],
153+
154+
// Defined by Airbnb
155+
semi: 'off',
156+
'@typescript-eslint/semi': ['error', 'always'],
157+
158+
// Defined by NI
159+
'space-before-function-paren': 'off',
160+
'@typescript-eslint/space-before-function-paren': ['error', {
161+
anonymous: 'always',
162+
named: 'never',
163+
asyncArrow: 'always'
164+
}],
165+
166+
// Defined by Airbnb
167+
'space-infix-ops': 'off',
168+
'@typescript-eslint/space-infix-ops': 'error',
169+
}
170+
};

package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"main": "index.js",
66
"scripts": {
77
"prepare": "npm test",
8-
"test": "eslint ."
8+
"test": "eslint .",
9+
"test-typescript": "eslint ./test/typescript/",
10+
"test-typescript-typed": "eslint ./test/typescript-type-checking/",
11+
"dev-print-typescript-props": "node ./tools/print-typescript-properties"
912
},
1013
"repository": {
1114
"type": "git",
@@ -26,16 +29,18 @@
2629
"access": "public"
2730
},
2831
"files": [
29-
".eslintrc.js",
30-
"typescript.js"
32+
"/*.js",
33+
"/lib/*"
3134
],
3235
"dependencies": {
3336
"@typescript-eslint/parser": "^4.9.1",
3437
"eslint-config-airbnb-base": "~14.2.0"
3538
},
3639
"devDependencies": {
40+
"@typescript-eslint/eslint-plugin": "^4.9.1",
3741
"eslint": "^7.6.0",
38-
"eslint-plugin-import": "^2.22.0"
42+
"eslint-plugin-import": "^2.22.0",
43+
"typescript": "^4.1.3"
3944
},
4045
"peerDependencies": {
4146
"@typescript-eslint/eslint-plugin": "^4.9.1",

0 commit comments

Comments
 (0)