Skip to content

Commit e249109

Browse files
authored
fix(linter): fix line endings handling in '@nx/eslint:convert-to-flat-config' generator (#31043)
## Current Behavior When running `nx g @nx/eslint:convert-to-flat-config` on windows, the ignores path is not handled correctly. After converting, the path will have the additional `/r` ## Expected Behavior When running `nx g @nx/eslint:convert-to-flat-config` on windows, the ignores path should be correct.
1 parent b51676a commit e249109

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Tree, readJson } from '@nx/devkit';
22
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
33
import { convertEslintJsonToFlatConfig } from './json-converter';
4+
import { EOL } from 'node:os';
45

56
describe('convertEslintJsonToFlatConfig', () => {
67
let tree: Tree;
@@ -63,7 +64,7 @@ describe('convertEslintJsonToFlatConfig', () => {
6364
})
6465
);
6566

66-
tree.write('.eslintignore', 'node_modules\nsomething/else');
67+
tree.write('.eslintignore', `node_modules${EOL}something/else`);
6768

6869
const { content } = convertEslintJsonToFlatConfig(
6970
tree,
@@ -227,7 +228,7 @@ describe('convertEslintJsonToFlatConfig', () => {
227228
})
228229
);
229230

230-
tree.write('mylib/.eslintignore', 'node_modules\nsomething/else');
231+
tree.write('mylib/.eslintignore', `node_modules${EOL}something/else`);
231232

232233
const { content } = convertEslintJsonToFlatConfig(
233234
tree,
@@ -376,7 +377,7 @@ describe('convertEslintJsonToFlatConfig', () => {
376377
})
377378
);
378379

379-
tree.write('.eslintignore', 'node_modules\nsomething/else');
380+
tree.write('.eslintignore', `node_modules${EOL}something/else`);
380381

381382
const { content } = convertEslintJsonToFlatConfig(
382383
tree,
@@ -537,7 +538,7 @@ describe('convertEslintJsonToFlatConfig', () => {
537538
})
538539
);
539540

540-
tree.write('mylib/.eslintignore', 'node_modules\nsomething/else');
541+
tree.write('mylib/.eslintignore', `node_modules${EOL}something/else`);
541542

542543
const { content } = convertEslintJsonToFlatConfig(
543544
tree,

packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function convertEslintJsonToFlatConfig(
185185
if (tree.exists(ignorePath)) {
186186
const patterns = tree
187187
.read(ignorePath, 'utf-8')
188-
.split('\n')
188+
.split(/\r\n|\r|\n/)
189189
.filter((line) => line.length > 0 && line !== 'node_modules')
190190
.map((path) => mapFilePath(path));
191191
if (patterns.length > 0) {

0 commit comments

Comments
 (0)