Skip to content

Commit

Permalink
fix(NOJIRA-123): strict typechecks enable noImplicitAny by default
Browse files Browse the repository at this point in the history
As pointed out by @rafaell-lycan, enabling compilerOptions.strict in turn enables compilerOptions.noImplicitAny by default - unless overridden.
Update logic to account for this.
  • Loading branch information
trapped authored Aug 8, 2023
2 parents 44de8f2 + 26a1e19 commit 011bd86
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/checks/requiredTypeScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,25 @@ describe('missingTsConfigSettings', () => {
})
).not.toContainEqual(expect.stringMatching(/compilerOptions.noImplicitAny/))
})
it('considers compilerOptions.noImplicitAny = true if compilerOptions.strict = true', () => {
expect(
missingTsConfigSettings({
compilerOptions: {
strict: true,
allowUnreachableCode: false,
},
})
).not.toContainEqual(expect.stringMatching(/compilerOptions.noImplicitAny/))
})
it('requires not setting compilerOptions.noImplicitAny = false if compilerOptions.strict = true', () => {
expect(
missingTsConfigSettings({
compilerOptions: {
strict: true,
noImplicitAny: false,
allowUnreachableCode: false,
},
})
).toContainEqual(expect.stringMatching(/compilerOptions.noImplicitAny/))
})
})
7 changes: 6 additions & 1 deletion src/checks/requiredTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ignore, { Ignore as IgnoredFileFilter } from 'ignore'

type TsConfig = {
compilerOptions?: {
strict?: boolean
allowUnreachableCode?: boolean
noImplicitAny?: boolean
}
Expand Down Expand Up @@ -208,7 +209,11 @@ export function missingTsConfigSettings(tsconfig: TsConfig): string[] {
errors.push('compilerOptions.allowUnreachableCode must be false')
}

if (tsconfig.compilerOptions?.noImplicitAny !== true) {
if (
(tsconfig.compilerOptions?.strict !== true &&
tsconfig.compilerOptions?.noImplicitAny !== true) ||
tsconfig.compilerOptions?.noImplicitAny === false
) {
errors.push('compilerOptions.noImplicitAny must be true')
}

Expand Down

0 comments on commit 011bd86

Please sign in to comment.