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.
This commit is contained in:
parent
b51676a89a
commit
e249109615
@ -1,6 +1,7 @@
|
||||
import { Tree, readJson } from '@nx/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import { convertEslintJsonToFlatConfig } from './json-converter';
|
||||
import { EOL } from 'node:os';
|
||||
|
||||
describe('convertEslintJsonToFlatConfig', () => {
|
||||
let tree: Tree;
|
||||
@ -63,7 +64,7 @@ describe('convertEslintJsonToFlatConfig', () => {
|
||||
})
|
||||
);
|
||||
|
||||
tree.write('.eslintignore', 'node_modules\nsomething/else');
|
||||
tree.write('.eslintignore', `node_modules${EOL}something/else`);
|
||||
|
||||
const { content } = convertEslintJsonToFlatConfig(
|
||||
tree,
|
||||
@ -227,7 +228,7 @@ describe('convertEslintJsonToFlatConfig', () => {
|
||||
})
|
||||
);
|
||||
|
||||
tree.write('mylib/.eslintignore', 'node_modules\nsomething/else');
|
||||
tree.write('mylib/.eslintignore', `node_modules${EOL}something/else`);
|
||||
|
||||
const { content } = convertEslintJsonToFlatConfig(
|
||||
tree,
|
||||
@ -376,7 +377,7 @@ describe('convertEslintJsonToFlatConfig', () => {
|
||||
})
|
||||
);
|
||||
|
||||
tree.write('.eslintignore', 'node_modules\nsomething/else');
|
||||
tree.write('.eslintignore', `node_modules${EOL}something/else`);
|
||||
|
||||
const { content } = convertEslintJsonToFlatConfig(
|
||||
tree,
|
||||
@ -537,7 +538,7 @@ describe('convertEslintJsonToFlatConfig', () => {
|
||||
})
|
||||
);
|
||||
|
||||
tree.write('mylib/.eslintignore', 'node_modules\nsomething/else');
|
||||
tree.write('mylib/.eslintignore', `node_modules${EOL}something/else`);
|
||||
|
||||
const { content } = convertEslintJsonToFlatConfig(
|
||||
tree,
|
||||
|
||||
@ -185,7 +185,7 @@ export function convertEslintJsonToFlatConfig(
|
||||
if (tree.exists(ignorePath)) {
|
||||
const patterns = tree
|
||||
.read(ignorePath, 'utf-8')
|
||||
.split('\n')
|
||||
.split(/\r\n|\r|\n/)
|
||||
.filter((line) => line.length > 0 && line !== 'node_modules')
|
||||
.map((path) => mapFilePath(path));
|
||||
if (patterns.length > 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user