Skip to content

Commit 2970a44

Browse files
gavinbarronmusale
andauthored
feat: migrate to eslint (#2125)
adds eslint and @typescript-eslint to the project refactoring to fix eslint issues massive amounts of typing added to async calls lots of floating promises either properly awaited of explicitly set to void added linting to pre-commit hook removed tslint packages and directives removed lint from pre-commit hook and moving it to the PR pipeline fixed MsalProvider tests added PascalCase naming convention to allow React components to follow their naming conventions added eslint to recommended vscode extensions changing card embeding logic for person-card sections Co-authored-by: Musale Martin <[email protected]>
1 parent 670a3cb commit 2970a44

File tree

145 files changed

+3712
-3368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+3712
-3368
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"runem.lit-plugin",
99
"esbenp.prettier-vscode",
1010
"rebornix.project-snippets",
11-
"ms-vscode.vscode-typescript-tslint-plugin",
11+
"dbaeumer.vscode-eslint",
1212
"mutantdino.resourcemonitor"
1313
]
1414
}

.eslintrc.js

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/*
2+
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3+
https://github.com/typescript-eslint/tslint-to-eslint-config
4+
5+
It represents the closest reasonable ESLint configuration to this
6+
project's original TSLint configuration.
7+
8+
We recommend eventually switching this configuration to extend from
9+
the recommended rulesets in typescript-eslint.
10+
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11+
12+
Happy linting! 💖
13+
*/
14+
module.exports = {
15+
env: {
16+
browser: true,
17+
es6: true,
18+
node: true
19+
},
20+
extends: ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking'],
21+
parser: '@typescript-eslint/parser',
22+
parserOptions: {
23+
project: [
24+
'packages/mgt/tsconfig.json',
25+
'packages/mgt-element/tsconfig.json',
26+
'packages/mgt-components/tsconfig.json',
27+
'packages/mgt-react/tsconfig.json',
28+
'packages/mgt-spfx/tsconfig.json',
29+
'packages/mgt-spfx-utils/tsconfig.json',
30+
'packages/providers/mgt-electron-provider/tsconfig.authenticator.json',
31+
'packages/providers/mgt-electron-provider/tsconfig.provider.json',
32+
'packages/providers/mgt-mock-provider/tsconfig.json',
33+
'packages/providers/mgt-msal-provider/tsconfig.json',
34+
'packages/providers/mgt-msal2-provider/tsconfig.json',
35+
'packages/providers/mgt-proxy-provider/tsconfig.json',
36+
'packages/providers/mgt-sharepoint-provider/tsconfig.json',
37+
'packages/providers/mgt-teams-msal2-provider/tsconfig.json',
38+
'packages/providers/mgt-teams-provider/tsconfig.json',
39+
'packages/providers/mgt-teamsfx-provider/tsconfig.json'
40+
],
41+
sourceType: 'module'
42+
},
43+
plugins: [
44+
'eslint-plugin-jsdoc',
45+
'eslint-plugin-prefer-arrow',
46+
'eslint-plugin-react',
47+
'@typescript-eslint',
48+
'@typescript-eslint/tslint'
49+
],
50+
root: true,
51+
ignorePatterns: ['**/**-css.ts', '.eslintrc.js'],
52+
rules: {
53+
'@typescript-eslint/adjacent-overload-signatures': 'error',
54+
'@typescript-eslint/array-type': [
55+
'error',
56+
{
57+
default: 'array'
58+
}
59+
],
60+
'@typescript-eslint/ban-types': [
61+
'error',
62+
{
63+
types: {
64+
Object: {
65+
message: 'Avoid using the `Object` type. Did you mean `object`?'
66+
},
67+
Function: {
68+
message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.'
69+
},
70+
Boolean: {
71+
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?'
72+
},
73+
Number: {
74+
message: 'Avoid using the `Number` type. Did you mean `number`?'
75+
},
76+
String: {
77+
message: 'Avoid using the `String` type. Did you mean `string`?'
78+
},
79+
Symbol: {
80+
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?'
81+
}
82+
}
83+
}
84+
],
85+
'@typescript-eslint/consistent-type-assertions': 'error',
86+
'@typescript-eslint/dot-notation': 'error',
87+
'@typescript-eslint/explicit-function-return-type': 'off',
88+
'@typescript-eslint/explicit-module-boundary-types': 'off',
89+
'@typescript-eslint/indent': 'off',
90+
'@typescript-eslint/member-delimiter-style': [
91+
'off',
92+
{
93+
multiline: {
94+
delimiter: 'none',
95+
requireLast: true
96+
},
97+
singleline: {
98+
delimiter: 'semi',
99+
requireLast: false
100+
}
101+
}
102+
],
103+
'@typescript-eslint/naming-convention': [
104+
'warn',
105+
{
106+
selector: 'variable',
107+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
108+
leadingUnderscore: 'forbid',
109+
trailingUnderscore: 'forbid'
110+
},
111+
{
112+
selector: ['property', 'accessor'],
113+
modifiers: ['private'],
114+
format: ['camelCase'],
115+
leadingUnderscore: 'allow'
116+
},
117+
{
118+
selector: ['variable', 'function'],
119+
format: ['camelCase'],
120+
leadingUnderscore: 'allow'
121+
}
122+
],
123+
'@typescript-eslint/no-empty-function': 'error',
124+
'@typescript-eslint/no-empty-interface': 'error',
125+
'@typescript-eslint/no-explicit-any': 'off',
126+
'@typescript-eslint/no-misused-new': 'error',
127+
'@typescript-eslint/no-namespace': 'error',
128+
'@typescript-eslint/no-parameter-properties': 'off',
129+
'@typescript-eslint/no-shadow': [
130+
'error',
131+
{
132+
hoist: 'all'
133+
}
134+
],
135+
'@typescript-eslint/no-unused-expressions': 'error',
136+
'@typescript-eslint/no-use-before-define': 'off',
137+
'@typescript-eslint/no-var-requires': 'error',
138+
'@typescript-eslint/prefer-for-of': 'error',
139+
'@typescript-eslint/prefer-function-type': 'error',
140+
'@typescript-eslint/prefer-namespace-keyword': 'error',
141+
'@typescript-eslint/quotes': [
142+
'error',
143+
'single',
144+
{
145+
avoidEscape: true
146+
}
147+
],
148+
'@typescript-eslint/restrict-template-expressions': ['error', { allowBoolean: true, allowNumber: true }],
149+
'@typescript-eslint/semi': ['off', null],
150+
'@typescript-eslint/triple-slash-reference': [
151+
'error',
152+
{
153+
path: 'always',
154+
types: 'prefer-import',
155+
lib: 'always'
156+
}
157+
],
158+
'@typescript-eslint/type-annotation-spacing': 'off',
159+
'@typescript-eslint/typedef': 'off',
160+
'@typescript-eslint/unified-signatures': 'error',
161+
'arrow-parens': ['off', 'always'],
162+
'brace-style': ['off', 'off'],
163+
'comma-dangle': 'off',
164+
complexity: 'off',
165+
'constructor-super': 'error',
166+
'dot-notation': 'off',
167+
'eol-last': 'off',
168+
eqeqeq: ['error', 'smart'],
169+
'guard-for-in': 'error',
170+
'id-denylist': 'error',
171+
'id-match': 'error',
172+
indent: 'off',
173+
'jsdoc/check-alignment': 'error',
174+
'jsdoc/check-indentation': 'error',
175+
'jsdoc/newline-after-description': 'error',
176+
'linebreak-style': 'off',
177+
'max-classes-per-file': ['error', 1],
178+
'max-len': 'off',
179+
'new-parens': 'off',
180+
'newline-per-chained-call': 'off',
181+
'no-bitwise': 'error',
182+
'no-caller': 'error',
183+
'no-cond-assign': 'error',
184+
'no-console': 'error',
185+
'no-debugger': 'error',
186+
'no-empty': 'error',
187+
'no-empty-function': 'off',
188+
'no-eval': 'error',
189+
'no-extra-semi': 'off',
190+
'no-fallthrough': 'off',
191+
'no-invalid-this': 'off',
192+
'no-irregular-whitespace': 'off',
193+
'no-multiple-empty-lines': 'off',
194+
'no-new-wrappers': 'error',
195+
'no-shadow': 'off',
196+
'no-throw-literal': 'error',
197+
'no-trailing-spaces': 'off',
198+
'no-undef-init': 'error',
199+
'no-underscore-dangle': 'off',
200+
'no-unsafe-finally': 'error',
201+
'no-unused-expressions': 'off',
202+
'no-unused-labels': 'error',
203+
'no-use-before-define': 'off',
204+
'no-var': 'error',
205+
'object-shorthand': 'error',
206+
'one-var': ['error', 'never'],
207+
'padded-blocks': [
208+
'off',
209+
{
210+
blocks: 'never'
211+
},
212+
{
213+
allowSingleLineBlocks: true
214+
}
215+
],
216+
'prefer-arrow/prefer-arrow-functions': 'error',
217+
'prefer-const': 'error',
218+
'quote-props': 'off',
219+
quotes: 'off',
220+
radix: 'error',
221+
'react/jsx-curly-spacing': 'off',
222+
'react/jsx-equals-spacing': 'off',
223+
'react/jsx-tag-spacing': [
224+
'off',
225+
{
226+
afterOpening: 'allow',
227+
closingSlash: 'allow'
228+
}
229+
],
230+
'react/jsx-wrap-multilines': 'off',
231+
semi: 'off',
232+
'space-before-function-paren': 'off',
233+
'space-in-parens': ['off', 'never'],
234+
'spaced-comment': [
235+
'error',
236+
'always',
237+
{
238+
markers: ['/']
239+
}
240+
],
241+
'use-isnan': 'error',
242+
'valid-typeof': 'off',
243+
'@typescript-eslint/tslint/config': [
244+
'warn',
245+
{
246+
rules: {
247+
'completed-docs': [
248+
true,
249+
{
250+
methods: {
251+
privacies: ['public', 'protected']
252+
},
253+
properties: {
254+
privacies: ['public', 'protected']
255+
},
256+
classes: true,
257+
enums: true,
258+
'enum-members': true,
259+
functions: true,
260+
interfaces: true,
261+
namespaces: true,
262+
types: true,
263+
variables: true
264+
}
265+
]
266+
}
267+
}
268+
]
269+
}
270+
};

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
if: steps.cache-node-modules.outputs.cache-hit != 'true'
3737
run: yarn
3838
- run: node scripts/setVersion.js --next
39-
- run: yarn run tsc -v
4039
- run: yarn build
40+
- run: yarn lint
4141
- run: yarn test
4242
- name: Archive test results
4343
uses: actions/upload-artifact@v2 # upload test results

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"bierner.lit-html",
77
"esbenp.prettier-vscode",
88
"rebornix.project-snippets",
9-
"ms-vscode.vscode-typescript-tslint-plugin"
9+
"dbaeumer.vscode-eslint"
1010
]
1111
}

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ <h2>mgt-login</h2>
7474
<mgt-login login-view="compact"></mgt-login>
7575
<mgt-login></mgt-login>
7676
<h2>mgt-person me query two lines card on click with presence</h2>
77-
<mgt-person person-query="me" view="twoLines" person-card="click" show-presence></mgt-person>
78-
<h2>mgt-people-picker</h2>
77+
<!-- <mgt-person person-query="me" view="twoLines" person-card="click" show-presence></mgt-person> -->
78+
<mgt-person-card person-query="me"></mgt-person-card>
79+
<!-- <h2>mgt-people-picker</h2>
7980
<mgt-people-picker></mgt-people-picker>
8081
<h2>mgt-teams-channel-picker</h2>
8182
<mgt-teams-channel-picker></mgt-teams-channel-picker>
@@ -90,7 +91,7 @@ <h2>mgt-todo</h2>
9091
<h2>mgt-file-list</h2>
9192
<mgt-file-list></mgt-file-list>
9293
<h2>mgt-picker</h2>
93-
<mgt-picker resource="me/todo/lists" scopes="tasks.read, tasks.readwrite"></mgt-picker>
94+
<mgt-picker resource="me/todo/lists" scopes="tasks.read, tasks.readwrite"></mgt-picker> -->
9495
</main>
9596
</body>
9697
</html>

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build:mgt-element": "cd ./packages/mgt-element && npm run build",
3030
"build:mgt-components": "cd ./packages/mgt-components && npm run build",
3131
"build:mgt-react": "lerna run build --scope @microsoft/mgt-react",
32+
"build:mgt-spfx": "lerna run build --scope @microsoft/mgt-spfx",
3233
"build:sp-webpart": "lerna run build --scope mgt-demo",
3334
"build:sp-mgt": "lerna run build --scope sp-mgt-no-framework",
3435
"package:sp-webpart": "lerna run package --scope mgt-demo",
@@ -37,7 +38,7 @@
3738
"bootstrap": "lerna bootstrap --useWorkspaces",
3839
"clean": "lerna run --parallel --stream --scope @microsoft/* clean",
3940
"link": "lerna link --force-local",
40-
"lint": "lerna run --parallel --stream --scope @microsoft/* lint",
41+
"lint": "eslint -c .eslintrc.js 'packages/*/src/**/*.ts'",
4142
"pack": "shx rm -rf artifacts/*.tgz && lerna exec --stream --scope @microsoft/* -- npm pack",
4243
"prepare": "lerna bootstrap --force-local",
4344
"sass": "lerna run sass --scope @microsoft/*",
@@ -95,11 +96,19 @@
9596
"@types/node": "12.12.22",
9697
"@types/react": "^17.0.00",
9798
"@types/react-dom": "^17.0.0",
99+
"@typescript-eslint/eslint-plugin": "^5.54.0",
100+
"@typescript-eslint/eslint-plugin-tslint": "^5.54.0",
101+
"@typescript-eslint/parser": "^5.54.0",
98102
"@web/dev-server": "^0.1.10",
99103
"@webcomponents/webcomponentsjs": "^2.5.0",
100104
"babel-loader": "^8.2.1",
101105
"core-js": "^3.7.0",
102106
"cpx": "^1.5.0",
107+
"eslint": "^8.35.0",
108+
"eslint-config-prettier": "^8.6.0",
109+
"eslint-plugin-jsdoc": "^40.0.0",
110+
"eslint-plugin-prefer-arrow": "^1.2.3",
111+
"eslint-plugin-react": "^7.32.2",
103112
"fs-extra": "^9.0.1",
104113
"gulp": "^4.0.2",
105114
"gulp-append-prepend": "^1.0.8",
@@ -139,9 +148,6 @@
139148
"storybook-version": "^0.1.1",
140149
"testing-library__dom": "^7.29.4-beta.1",
141150
"ts-jest": "^29.0.3",
142-
"tslint": "^6.1.3",
143-
"tslint-config-prettier": "^1.18.0",
144-
"tslint-microsoft-contrib": "^6.2.0",
145151
"typescript": "^4.9.4",
146152
"web-component-analyzer": "^1.1.6",
147153
"whatwg-fetch": "^3.6.2"
@@ -160,6 +166,9 @@
160166
},
161167
"resolutions": {
162168
"@microsoft/microsoft-graph-client": "3.0.2",
169+
"@typescript-eslint/eslint-plugin": "^5.54.0",
170+
"@typescript-eslint/eslint-plugin-tslint": "^5.54.0",
171+
"@typescript-eslint/parser": "^5.54.0",
163172
"responselike": "2.0.0"
164173
}
165174
}

packages/mgt-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"clean": "shx rm -rf ./dist && shx rm -rf ./tsconfig.tsbuildinfo",
3131
"compile": "tsc -b",
3232
"compile:watch": "tsc -w",
33-
"lint": "tslint -c ../../tslint.json 'src/**/*.ts'",
33+
"lint": "eslint -c ../../.eslintrc.js 'src/**/*.ts'",
3434
"postpack": "cpx *.tgz ../../artifacts",
3535
"sass": "gulp sass --cwd .",
3636
"sass:watch": "gulp watchSass --cwd ."

0 commit comments

Comments
 (0)