Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.5.0] - 2025-11-18

### Added

- Add script `check-strict-comments` to remove `//@ts-strict-ignore` comments on files already strict

## [2.4.1] - 2024-04-09

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ just need to run:
update-strict-comments
```

## Check for files already strict and remove `//@ts-strict-ignore` comments

When working on a large project, files can become strict without the authors noticing. Unless someone removes the `//@ts-strict-ignore` comment, the file will remain non-strict longer than necessary. To clean up such files and see the actual progress you can run:

```
check-strict-comments
```

## VSCode support

VSCode supports this plugin out of the box. However, sometimes it can use its own typescript version
Expand Down
18 changes: 15 additions & 3 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-strict-plugin",
"version": "2.4.4",
"version": "2.5.0",
"description": "Typescript tools that help with migration to the strict mode",
"author": "Allegro",
"contributors": [
Expand All @@ -22,7 +22,8 @@
"license": "MIT",
"bin": {
"tsc-strict": "dist/cli/tsc-strict/index.js",
"update-strict-comments": "dist/cli/update-strict-comments/index.js"
"update-strict-comments": "dist/cli/update-strict-comments/index.js",
"check-strict-comments": "dist/cli/check-strict-comments/index.js"
},
"main": "dist/plugin/index.js",
"private": false,
Expand Down
43 changes: 24 additions & 19 deletions sample-project/package-lock.json

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

21 changes: 21 additions & 0 deletions sample-project/src/alreadyStrict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-strict-ignore
export {}; // make this file a module to avoid global redeclaration errors

interface TestType {
bar: string;
}

const getFoo = (): TestType | undefined => {
// Simulate fetching or computing the value
return Math.random() > 0.5 ? { bar: 'value from getFoo' } : undefined;
}

const foo: TestType | undefined = getFoo();

const isTestType = (obj: unknown): obj is TestType => {
if (obj == null || typeof obj !== 'object') return false;
if (!Object.prototype.hasOwnProperty.call(obj, 'bar')) return false;
return typeof (obj as Record<string, unknown>).bar === 'string';
}

const barValue: string = isTestType(foo) ? foo.bar : 'some default value';
15 changes: 15 additions & 0 deletions sample-project/src/notStrict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-strict-ignore
export {}; // make this file a module to avoid global redeclaration errors

interface TestType {
bar: string;
}

const getFoo = (): TestType | undefined => {
// Simulate fetching or computing the value
return Math.random() > 0.5 ? { bar: 'value from getFoo' } : undefined;
}

const foo: TestType | undefined = getFoo();

const barValue: string = foo.bar;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { mocked } from 'jest-mock';
import { readFileSync, writeFileSync } from 'fs';
import { insertIgnoreComment, removeStrictComment } from '../commentOperations';
import {
insertIgnoreComment,
removeIgnoreComment,
removeStrictComment,
} from '../commentOperations';

jest.mock('fs', () => ({
readFileSync: jest.fn(),
Expand All @@ -27,6 +31,34 @@ describe('insertIgnoreComment', () => {
});
});

describe('removeIgnoreComment', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should remove comment', () => {
// given
readFileSyncMock.mockReturnValue('// @ts-strict-ignore\nconst x = 0;');

// when
removeIgnoreComment('file.ts');

// then
expect(writeFileSyncMock).toBeCalledWith('file.ts', 'const x = 0;');
});

it('should not change file content without strict comment', () => {
// given
readFileSyncMock.mockReturnValue('const x = 0;');

// when
removeIgnoreComment('file.ts');

// then
expect(writeFileSyncMock).not.toBeCalled();
});
});

describe('removeStrictComment', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Loading