Skip to content

Commit

Permalink
update-strict-comments removes ts-strict comment in strict files with…
Browse files Browse the repository at this point in the history
…out errors (#23)
  • Loading branch information
kamkry authored Jan 24, 2022
1 parent 4d3f05f commit 70b6197
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-strict-plugin",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"description": "Typescript tools that help with migration to the strict mode",
"author": "Allegro",
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mocked } from 'jest-mock';
import { isIgnoreCommentPresent, isStrictCommentPresent } from '../../isCommentPresent';
import { getFilePathsWithErrors, getFilePathsWithoutErrors } from '../getFilePaths';
import { getFilePathsWithErrors, getFilePathsOnPathWithoutErrors } from '../getFilePaths';
import { updateStrictComments } from '../updateStrictComments';
import { insertIgnoreComment, removeStrictComment } from '../commentOperations';

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

jest.mock('../getFilePaths', () => ({
getFilePathsWithErrors: jest.fn(),
getFilePathsWithoutErrors: jest.fn(),
getFilePathsOnPathWithoutErrors: jest.fn(),
}));

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

const getFilePathsWithErrorsMock = mocked(getFilePathsWithErrors);
const getFilePathsWithoutErrorsMock = mocked(getFilePathsWithoutErrors);
const getFilePathsOnPathWithoutErrorsMock = mocked(getFilePathsOnPathWithoutErrors);

const isStrictCommentPresentMock = mocked(isStrictCommentPresent);
const isIgnoreCommentPresentMock = mocked(isIgnoreCommentPresent);
Expand All @@ -33,7 +33,7 @@ describe('updateStrictComments', () => {
beforeEach(() => {
jest.resetAllMocks();
getFilePathsWithErrorsMock.mockResolvedValue([]);
getFilePathsWithoutErrorsMock.mockReturnValue([]);
getFilePathsOnPathWithoutErrorsMock.mockReturnValue([]);
});

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

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

Expand Down
5 changes: 2 additions & 3 deletions src/cli/update-strict-comments/getFilePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ export const getFilePathsWithErrors = async (allFilePaths: string[]) => {
return [...new Set(errors.map(getFilePathFromErrorMessage))];
};

// Returns an array of file paths that are on config path and do not contain strict errors
export const getFilePathsWithoutErrors = (
export const getFilePathsOnPathWithoutErrors = (
allFilePaths: string[],
filePathsWithErrors: string[],
configPaths?: string[],
) =>
allFilePaths.filter(
(filePath) =>
!isFileStrictByPath(filePath, configPaths) && !filePathsWithErrors.includes(filePath),
isFileStrictByPath(filePath, configPaths) && !filePathsWithErrors.includes(filePath),
);
5 changes: 2 additions & 3 deletions src/cli/update-strict-comments/updateStrictComments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getFilePathsWithErrors, getFilePathsWithoutErrors } from './getFilePaths';
import { getFilePathsWithErrors, getFilePathsOnPathWithoutErrors } from './getFilePaths';
import { isIgnoreCommentPresent, isStrictCommentPresent } from '../isCommentPresent';
import { isFileStrictByPath } from '../../common/isFileStrictByPath';
import { file } from 'tmp-promise';
import { insertIgnoreComment, removeStrictComment } from './commentOperations';

interface UpdateStrictCommentsResult {
Expand All @@ -13,7 +12,7 @@ export async function updateStrictComments(
configPaths?: string[],
): Promise<UpdateStrictCommentsResult> {
const filesWithErrors = await getFilePathsWithErrors(filePaths);
const filesOnPathWithoutErrors = getFilePathsWithoutErrors(
const filesOnPathWithoutErrors = getFilePathsOnPathWithoutErrors(
filePaths,
filesWithErrors,
configPaths,
Expand Down

0 comments on commit 70b6197

Please sign in to comment.