Skip to content

Commit

Permalink
chore: enable multiple new tsconfig safety flags
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Dec 24, 2024
1 parent 3b3d2d5 commit c9f74b0
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/stores/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export let toggleTheme = (): void => {
}

onSet(theme, ({ newValue }) => {
document.documentElement.dataset.theme =
document.documentElement.dataset['theme'] =
newValue === 'dark' ? 'dark' : 'light'
})
11 changes: 7 additions & 4 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
]
let isStyle = (value: string): boolean => {
let [cleanedValue] = value.split('?')
return styleExtensions.some(extension => cleanedValue.endsWith(extension))
return styleExtensions.some(extension =>
cleanedValue?.endsWith(extension),
)
}

let flatGroups = new Set(options.groups.flat())
Expand Down Expand Up @@ -290,10 +292,11 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
'ws',
]
let builtinPrefixOnlyModules = ['sea', 'sqlite', 'test']
let valueToCheck = value.startsWith('node:')
? value.split('node:')[1]
: value
return (
builtinModules.includes(
value.startsWith('node:') ? value.split('node:')[1] : value,
) ||
(!!valueToCheck && builtinModules.includes(valueToCheck)) ||
builtinPrefixOnlyModules.some(module => `node:${module}` === value) ||
(options.environment === 'bun' ? bunModules.includes(value) : false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('readClosestTsConfigByPath', () => {
'../../../rules/sort-imports/get-typescript-import',
)
mockGetTypescriptImport.mockImplementation(
actualGetTypescriptImport.getTypescriptImport as never,
actualGetTypescriptImport['getTypescriptImport'] as never,
)
})

Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"include": ["**/*.svelte", "**/*.astro", "**/*.ts"],
"exclude": ["node_modules", "coverage"],
"compilerOptions": {
"noPropertyAccessFromIndexSignature": true,
"forceConsistentCasingInFileNames": true,
"noUncheckedIndexedAccess": true,
"allowUnreachableCode": false,
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"esModuleInterop": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"module": "esnext",
"target": "esnext",
Expand Down
6 changes: 3 additions & 3 deletions utils/alphabet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class Alphabet {
continue
}
}
this._characters[index] = this._characters[otherCharacterIndex]
this._characters[index] = this._characters[otherCharacterIndex]!
this._characters[otherCharacterIndex] = character
}
return this
Expand Down Expand Up @@ -209,7 +209,7 @@ export class Alphabet {
),
]
for (let [i, element] of charactersWithCase.entries()) {
this._characters[element.index] = orderedCharacters[i].character
this._characters[element.index] = orderedCharacters[i]!.character
}
return this
}
Expand Down Expand Up @@ -405,7 +405,7 @@ export class Alphabet {
0,
this._characters[
type === 'before' ? indexOfCharacterBefore : indexOfCharacterAfter
],
]!,
)
this._characters.splice(
type === 'before' ? indexOfCharacterBefore + 1 : indexOfCharacterAfter,
Expand Down
4 changes: 2 additions & 2 deletions utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ let getCustomSortingFunction = <T extends SortingNode>(
let minLength = Math.min(aValue.length, bValue.length)
// Iterate character by character.
for (let i = 0; i < minLength; i++) {
let aCharacter = aValue[i]
let bCharacter = bValue[i]
let aCharacter = aValue[i]!
let bCharacter = bValue[i]!
let indexOfA = indexByCharacters.get(aCharacter)
let indexOfB = indexByCharacters.get(bCharacter)
indexOfA ??= Infinity
Expand Down
4 changes: 2 additions & 2 deletions utils/generate-predefined-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ let getPermutations = (elements: string[]): string[][] => {
return
}
for (let i = first; i < elements.length; i++) {
;[elements[first], elements[i]] = [elements[i], elements[first]]
;[elements[first], elements[i]] = [elements[i]!, elements[first]!]
backtrack(first + 1)
;[elements[first], elements[i]] = [elements[i], elements[first]]
;[elements[first], elements[i]] = [elements[i]!, elements[first]]
}
}
backtrack(0)
Expand Down
2 changes: 1 addition & 1 deletion utils/get-array-combinations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export let getArrayCombinations = (
return
}
for (let i = start; i < array.length; i++) {
comb.push(array[i])
comb.push(array[i]!)
backtrack(i + 1, comb)
comb.pop()
}
Expand Down
5 changes: 3 additions & 2 deletions utils/get-eslint-disabled-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ let getEslintDisabledRulesByType = (
}
let regexp = new RegExp(`^${eslintDisableDirective} ((?:.|\\s)*)$`)
let disabledRulesMatch = trimmedCommentValue.match(regexp)
if (!disabledRulesMatch) {
let disableRulesMatchValue = disabledRulesMatch?.[1]
if (!disableRulesMatchValue) {
return null
}
return disabledRulesMatch[1]
return disableRulesMatchValue
.split(',')
.map(rule => rule.trim())
.filter(rule => !!rule)
Expand Down
4 changes: 2 additions & 2 deletions utils/get-node-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export let getNodeRange = ({
*/
let relevantTopComment: TSESTree.Comment | undefined
for (let i = comments.length - 1; i >= 0; i--) {
let comment = comments[i]
let comment = comments[i]!

let eslintDisabledRules = getEslintDisabledRules(comment.value)
if (
Expand All @@ -71,7 +71,7 @@ export let getNodeRange = ({
let previousCommentOrNodeStartLine =
i === comments.length - 1
? node.loc.start.line
: comments[i + 1].loc.start.line
: comments[i + 1]!.loc.start.line
if (comment.loc.end.line !== previousCommentOrNodeStartLine - 1) {
break
}
Expand Down
2 changes: 1 addition & 1 deletion utils/get-options-with-clean-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export let getOptionsWithCleanGroups = <T extends GroupOptions>(
})

let getCleanedNestedGroups = (nestedGroup: string[]): string[] | string =>
nestedGroup.length === 1 ? nestedGroup[0] : nestedGroup
nestedGroup.length === 1 && nestedGroup[0] ? nestedGroup[0] : nestedGroup
9 changes: 6 additions & 3 deletions utils/get-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Settings = Partial<{
export let getSettings = (
settings: TSESLint.SharedConfigurationSettings = {},
): Settings => {
if (!settings.perfectionist) {
if (!settings['perfectionist']) {
return {}
}

Expand All @@ -37,7 +37,10 @@ export let getSettings = (
)
}

let perfectionistSettings = settings.perfectionist as Record<string, unknown>
let perfectionistSettings = settings['perfectionist'] as Record<
string,
unknown
>

let invalidOptions = getInvalidOptions(perfectionistSettings)
if (invalidOptions.length) {
Expand All @@ -46,5 +49,5 @@ export let getSettings = (
)
}

return settings.perfectionist as Settings
return settings['perfectionist'] as Settings
}
12 changes: 4 additions & 8 deletions utils/sort-nodes-by-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,17 @@ export let sortNodesByGroups = <T extends SortingNode>(
let compareOptions = extraOptions?.getGroupCompareOptions
? extraOptions.getGroupCompareOptions(Number(groupNumber))
: options
let nodesToPush = nodesByNonIgnoredGroupNumber[Number(groupNumber)]!
if (!compareOptions) {
sortedNodes.push(...nodesByNonIgnoredGroupNumber[Number(groupNumber)])
sortedNodes.push(...nodesToPush)
continue
}
sortedNodes.push(
...sortNodes(
nodesByNonIgnoredGroupNumber[Number(groupNumber)],
compareOptions,
),
)
sortedNodes.push(...sortNodes(nodesToPush, compareOptions))
}

// Add ignored nodes at the same position as they were before linting.
for (let ignoredIndex of ignoredNodeIndices) {
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex]!)
}

return sortedNodes
Expand Down
2 changes: 1 addition & 1 deletion utils/sort-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export let sortNodes = <T extends SortingNode>(

// Add ignored nodes at the same position as they were before linting.
for (let ignoredIndex of ignoredNodeIndices) {
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex])
sortedNodes.splice(ignoredIndex, 0, nodes[ignoredIndex]!)
}

return sortedNodes
Expand Down

0 comments on commit c9f74b0

Please sign in to comment.