Skip to content

Commit 70b6197

Browse files
authored
update-strict-comments removes ts-strict comment in strict files without errors (#23)
1 parent 4d3f05f commit 70b6197

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-strict-plugin",
3-
"version": "2.0.0-beta.0",
3+
"version": "2.0.0-beta.1",
44
"description": "Typescript tools that help with migration to the strict mode",
55
"author": "Allegro",
66
"contributors": [

src/cli/update-strict-comments/__tests__/updateStrictComments.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mocked } from 'jest-mock';
22
import { isIgnoreCommentPresent, isStrictCommentPresent } from '../../isCommentPresent';
3-
import { getFilePathsWithErrors, getFilePathsWithoutErrors } from '../getFilePaths';
3+
import { getFilePathsWithErrors, getFilePathsOnPathWithoutErrors } from '../getFilePaths';
44
import { updateStrictComments } from '../updateStrictComments';
55
import { insertIgnoreComment, removeStrictComment } from '../commentOperations';
66

@@ -10,7 +10,7 @@ jest.mock('../../findStrictErrors', () => ({
1010

1111
jest.mock('../getFilePaths', () => ({
1212
getFilePathsWithErrors: jest.fn(),
13-
getFilePathsWithoutErrors: jest.fn(),
13+
getFilePathsOnPathWithoutErrors: jest.fn(),
1414
}));
1515

1616
jest.mock('../../isCommentPresent', () => ({
@@ -24,7 +24,7 @@ jest.mock('../commentOperations', () => ({
2424
}));
2525

2626
const getFilePathsWithErrorsMock = mocked(getFilePathsWithErrors);
27-
const getFilePathsWithoutErrorsMock = mocked(getFilePathsWithoutErrors);
27+
const getFilePathsOnPathWithoutErrorsMock = mocked(getFilePathsOnPathWithoutErrors);
2828

2929
const isStrictCommentPresentMock = mocked(isStrictCommentPresent);
3030
const isIgnoreCommentPresentMock = mocked(isIgnoreCommentPresent);
@@ -33,7 +33,7 @@ describe('updateStrictComments', () => {
3333
beforeEach(() => {
3434
jest.resetAllMocks();
3535
getFilePathsWithErrorsMock.mockResolvedValue([]);
36-
getFilePathsWithoutErrorsMock.mockReturnValue([]);
36+
getFilePathsOnPathWithoutErrorsMock.mockReturnValue([]);
3737
});
3838

3939
it('should not change comments when there is no strict errors in file', async () => {
@@ -89,7 +89,7 @@ describe('updateStrictComments', () => {
8989

9090
it('should remove strict comment when file is on configured path', async () => {
9191
// given
92-
getFilePathsWithoutErrorsMock.mockReturnValue(['/dir/file.ts']);
92+
getFilePathsOnPathWithoutErrorsMock.mockReturnValue(['/dir/file.ts']);
9393
isStrictCommentPresentMock.mockReturnValue(true);
9494
isIgnoreCommentPresentMock.mockReturnValue(false);
9595

src/cli/update-strict-comments/getFilePaths.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ export const getFilePathsWithErrors = async (allFilePaths: string[]) => {
1111
return [...new Set(errors.map(getFilePathFromErrorMessage))];
1212
};
1313

14-
// Returns an array of file paths that are on config path and do not contain strict errors
15-
export const getFilePathsWithoutErrors = (
14+
export const getFilePathsOnPathWithoutErrors = (
1615
allFilePaths: string[],
1716
filePathsWithErrors: string[],
1817
configPaths?: string[],
1918
) =>
2019
allFilePaths.filter(
2120
(filePath) =>
22-
!isFileStrictByPath(filePath, configPaths) && !filePathsWithErrors.includes(filePath),
21+
isFileStrictByPath(filePath, configPaths) && !filePathsWithErrors.includes(filePath),
2322
);

src/cli/update-strict-comments/updateStrictComments.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { getFilePathsWithErrors, getFilePathsWithoutErrors } from './getFilePaths';
1+
import { getFilePathsWithErrors, getFilePathsOnPathWithoutErrors } from './getFilePaths';
22
import { isIgnoreCommentPresent, isStrictCommentPresent } from '../isCommentPresent';
33
import { isFileStrictByPath } from '../../common/isFileStrictByPath';
4-
import { file } from 'tmp-promise';
54
import { insertIgnoreComment, removeStrictComment } from './commentOperations';
65

76
interface UpdateStrictCommentsResult {
@@ -13,7 +12,7 @@ export async function updateStrictComments(
1312
configPaths?: string[],
1413
): Promise<UpdateStrictCommentsResult> {
1514
const filesWithErrors = await getFilePathsWithErrors(filePaths);
16-
const filesOnPathWithoutErrors = getFilePathsWithoutErrors(
15+
const filesOnPathWithoutErrors = getFilePathsOnPathWithoutErrors(
1716
filePaths,
1817
filesWithErrors,
1918
configPaths,

0 commit comments

Comments
 (0)