Skip to content

Commit ff49e7d

Browse files
committed
finally enable eslint on typescript plugin codebase and do 300 fixes
1 parent 2d6ef50 commit ff49e7d

Some content is hidden

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

51 files changed

+257
-226
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# ignore files that have typescript import
2-
typescript/**
31
src/configurationType.ts
42
src/configurationTypeCache.jsonc
53
playground.ts

.eslintrc.json

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
{
22
"extends": "zardoy",
33
"rules": {
4-
"curly": "off"
5-
}
4+
"curly": "off",
5+
"import/no-deprecated": "off",
6+
// investigate why it is soooo slow...
7+
"import/no-named-as-default": "off",
8+
"import/no-named-as-default-member": "off",
9+
"default-case": "off",
10+
"sonarjs/no-duplicate-string": "off",
11+
"@typescript-eslint/naming-convention": "off",
12+
"no-empty-function": "off",
13+
"no-useless-return": "off",
14+
"no-template-curly-in-string": "off"
15+
},
16+
"overrides": [
17+
{
18+
"files": "typescript/**",
19+
"parserOptions": {
20+
"project": "typescript/tsconfig.json"
21+
},
22+
"rules": {
23+
"@typescript-eslint/padding-line-between-statements": "off",
24+
"arrow-body-style": "off",
25+
"import/no-extraneous-dependencies": "off",
26+
"@typescript-eslint/no-loop-func": "off",
27+
// always used intentionally as workaround for possibly undefined types (to not declare super complex types - cases)
28+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
29+
// todo configure instead
30+
"complexity": "off",
31+
"max-params": "off",
32+
"max-depth": "off",
33+
"@typescript-eslint/dot-notation": "off",
34+
"no-bitwise": "off",
35+
"@typescript-eslint/no-explicit-any": "off",
36+
// todo just not sure
37+
"@typescript-eslint/prefer-regexp-exec": "off",
38+
"unicorn/consistent-destructuring": "off",
39+
"no-negated-condition": "off",
40+
"@typescript-eslint/prefer-nullish-coalescing": "off",
41+
"unicorn/prefer-set-has": "off"
42+
}
43+
}
44+
]
645
}

typescript/src/adjustAutoImports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const findIndexOfAutoImportSpec = (ignoreAutoImportsSetting: ParsedIgnore
8888
if (!symbols.includes(symbol)) continue
8989
return i
9090
}
91-
return
91+
return undefined
9292
}
9393

9494
export const shouldChangeSortingOfAutoImport = (symbolName: string, c: GetConfig) => {
@@ -98,7 +98,7 @@ export const shouldChangeSortingOfAutoImport = (symbolName: string, c: GetConfig
9898

9999
export const changeSortingOfAutoImport = (c: GetConfig, symbolName: string): ((module: string) => number) => {
100100
const arr = c('autoImport.changeSorting')[symbolName]
101-
if (!arr || !arr.length) return () => 0
101+
if (!arr || arr.length === 0) return () => 0
102102
const maxIndex = arr.length
103103
return module => {
104104
let actualIndex = arr.findIndex(x => {

typescript/src/codeActions/custom/changeStringReplaceToRegex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { CodeAction } from '../getCodeActions'
21
import escapeStringRegexp from 'escape-string-regexp'
2+
import { CodeAction } from '../getCodeActions'
33
import { getChangesTracker } from '../../utils'
44

55
export default {

typescript/src/codeActions/custom/objectSwapKeysAndValues.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ export default {
4242
if (!name || ts.isPrivateIdentifier(name)) continue
4343
const initializerText = printNodeForObjectKey(initializer)
4444
if (!initializerText) continue
45-
edits.push({
46-
newText: initializerText,
47-
span: nodeToSpan(name),
48-
})
49-
edits.push({
50-
newText: ts.isComputedPropertyName(name)
51-
? name.expression.getText()
52-
: ts.isIdentifier(name)
53-
? /* TODO quote preference */ `'${name.text}'`
54-
: name.getText(),
55-
span: nodeToSpan(initializer),
56-
})
45+
edits.push(
46+
{
47+
newText: initializerText,
48+
span: nodeToSpan(name),
49+
},
50+
{
51+
newText: ts.isComputedPropertyName(name)
52+
? name.expression.getText()
53+
: ts.isIdentifier(name)
54+
? /* TODO quote preference */ `'${name.text}'`
55+
: name.getText(),
56+
span: nodeToSpan(initializer),
57+
},
58+
)
5759
}
5860
return {
5961
edits: [

typescript/src/codeActions/custom/toggleBraces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const tryToApply: ApplyCodeAction = (sourceFile, pos, range) => {
3131
{ start: wrapNode.getEnd(), length: 0, newText: `\n${startIndent}}` },
3232
]
3333
}
34-
return
3534
}
3635

3736
export default {

typescript/src/codeActions/decorateProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
1212
previousGetCodeActionsResult.value = compact(
1313
prior.flatMap(refactor => {
1414
const actions = refactor.actions.filter(action => !action.notApplicableReason).map(action => action.description)
15-
if (!actions.length) return
15+
if (actions.length === 0) return
1616
return actions.map(action => ({ description: refactor.description, name: action }))
1717
}),
1818
)

typescript/src/codeActions/extended/addMissingProperties.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
}
1717
// general patterns
1818
if (param.type && ts.isTypeLiteralNode(param.type) && param.type.members) {
19-
const hasMembers = param.type.members.length !== 0
19+
const hasMembers = param.type.members.length > 0
2020
const insertPos = param.type.members.at(-1)?.end ?? param.type.end - 1
2121
const insertComma = hasMembers && sourceFile.getFullText().slice(insertPos - 1, insertPos) !== ','
2222
let insertText = node.text
@@ -44,6 +44,5 @@ export default {
4444
}
4545
}
4646
}
47-
return
4847
},
4948
} as ExtendedCodeAction

typescript/src/codeActions/functionExtractors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const handleFunctionRefactorEdits = (
120120
},
121121
{
122122
span: functionChange.span,
123-
newText: oldFunctionText.match(/\s*/)![0] + newFunctionSignature.slice(0, -2) + '\n' + lines.slice(1).join('\n'),
123+
newText: `${oldFunctionText.match(/\s*/)![0] + newFunctionSignature.slice(0, -2)}\n${lines.slice(1).join('\n')}`,
124124
},
125125
],
126126
},
@@ -137,7 +137,7 @@ export const handleFunctionRefactorEdits = (
137137
functionChange.newText = oldFunctionText
138138
.replace(/function /, 'const ')
139139
.replace('(', ' = (')
140-
.replace(/\{\n/, '=> {\n')
140+
.replace(/{\n/, '=> {\n')
141141

142142
const isLocal = actionName.endsWith('_local_arrow')
143143
// to think: maybe reuse ts getNodeToInsertPropertyBefore instead?
@@ -150,7 +150,7 @@ export const handleFunctionRefactorEdits = (
150150
functionChange.span.start = constantAdd.span.start
151151
const indent = constantAdd.newText.match(/^\s*/)![0]
152152
// fix indent
153-
functionChange.newText = dedentString(functionChange.newText, indent, true) + '\n'
153+
functionChange.newText = `${dedentString(functionChange.newText, indent, true)}\n`
154154
}
155155

156156
// global scope

typescript/src/codeActions/getCodeActions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { compact } from '@zardoy/utils'
2+
import { Except } from 'type-fest'
23
import { findChildContainingExactPosition, findChildContainingPosition } from '../utils'
4+
import { ApplyExtendedCodeActionResult, IpcExtendedCodeAction } from '../ipcTypes'
35
import objectSwapKeysAndValues from './custom/objectSwapKeysAndValues'
46
import changeStringReplaceToRegex from './custom/changeStringReplaceToRegex'
57
import splitDeclarationAndInitialization from './custom/splitDeclarationAndInitialization'
68
import addMissingProperties from './extended/addMissingProperties'
7-
import { ApplyExtendedCodeActionResult, IpcExtendedCodeAction } from '../ipcTypes'
8-
import { Except } from 'type-fest'
99

1010
const codeActions: CodeAction[] = [objectSwapKeysAndValues, changeStringReplaceToRegex, splitDeclarationAndInitialization]
1111
const extendedCodeActions: ExtendedCodeAction[] = [addMissingProperties]
@@ -83,7 +83,7 @@ export const getExtendedCodeActions = <T extends string | undefined>(
8383
sourceFile,
8484
}
8585
if (applyCodeActionTitle) {
86-
const codeAction = extendedCodeActions.find(codeAction => codeAction.title === applyCodeActionTitle) as ExtendedCodeAction | undefined
86+
const codeAction = extendedCodeActions.find(codeAction => codeAction.title === applyCodeActionTitle)
8787
return codeAction!.tryToApply(tryToApplyOptions) as T extends undefined ? never : ApplyExtendedCodeActionResult
8888
}
8989
return compact(
@@ -144,7 +144,7 @@ export default (
144144
const requestingEdit: any = requestingEditsId ? appliableCodeActions.find(({ id }) => id === requestingEditsId) : null
145145
return {
146146
info:
147-
(appliableCodeActions.length && {
147+
(appliableCodeActions.length > 0 && {
148148
actions: appliableCodeActions.map(({ id, name, kind }) => ({
149149
description: name,
150150
kind,

0 commit comments

Comments
 (0)