Skip to content

Commit

Permalink
Enable "strict" compiler option (#2352)
Browse files Browse the repository at this point in the history
* Enable strict compiler option

* Create plenty-hounds-judge.md

* Add docs

* Adjust for falsy config values
  • Loading branch information
cristiano-belloni authored Apr 19, 2023
1 parent bdae623 commit ccffbfd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-hounds-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"modular-scripts": minor
---

Enable "strict" compiler option in the [typecheck allowlist](https://modular.js.org/commands/typecheck/#configuration)
1 change: 1 addition & 0 deletions docs/commands/typecheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ brings certain advantages:
There are certain exceptions for practical use cases. The current allowlist is:

- [jsx](https://www.typescriptlang.org/tsconfig#jsx)
- [strict](https://www.typescriptlang.org/tsconfig#strict)

Some use cases may warrant new exceptions. If this is you, please file an issue
with the project for consideration.
Expand Down
12 changes: 9 additions & 3 deletions packages/modular-scripts/src/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import actionPreflightCheck from './utils/actionPreflightCheck';
import { getAllWorkspaces } from './utils/getAllWorkspaces';
import { selectWorkspaces } from './utils/selectWorkspaces';

import type { JSONSchemaForTheTypeScriptCompilerSConfigurationFile as TSConfig } from '@schemastore/tsconfig';
import type {
JSONSchemaForTheTypeScriptCompilerSConfigurationFile as TSConfig,
CompilerOptionsDefinition,
} from '@schemastore/tsconfig';

type CompilerOptions = TSConfig['compilerOptions'];

Expand All @@ -19,7 +22,10 @@ export interface TypecheckOptions {
compareBranch: string;
}

const COMPILER_OPTIONS_ALLOW_LIST: string[] = ['jsx'];
const COMPILER_OPTIONS_ALLOW_LIST: (keyof CompilerOptionsDefinition)[] = [
'jsx',
'strict',
];
const DEFAULT_COMPILER_OPTIONS: CompilerOptions = {
noEmit: true,
};
Expand Down Expand Up @@ -55,7 +61,7 @@ function restrictUserTsconfig(

// Where the user has defined allowlist-supported compiler options, apply them
for (const item of COMPILER_OPTIONS_ALLOW_LIST) {
if (compilerOptions && compilerOptions[item]) {
if (compilerOptions?.[item] !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
combinedCompilerOptions[item] = compilerOptions[item];
}
Expand Down

0 comments on commit ccffbfd

Please sign in to comment.