Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(linter): Generator creating .eslintrc.json at the root path even …
…when .eslintrc.js already exist (#10080) * feat(devkit): feat(devkit): don't replace begining undescore when creating file Underscore is a character usually used for sorting purposes and is absolutely legit. There is no reason to replace it. ISSUES CLOSED: #8875 * fix(linter): generator creating .eslintrc.json at the root path even when .eslintrc.js
- Loading branch information
Showing
7 changed files
with
151 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/linter/src/generators/lint-project/__snapshots__/lint-project.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { containsEslint, findEslintFile } from './eslint-file'; | ||
|
||
import { Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
|
||
describe('@nrwl/linter:eslint-file', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
describe('containsEslint', () => { | ||
it('should return false when calling containsEslint without a eslint config', () => { | ||
expect(containsEslint(tree)).toBe(false); | ||
}); | ||
|
||
it('should return true when calling containsEslint with a .eslintrc.json config', () => { | ||
tree.write('.eslintrc.json', '{}'); | ||
expect(containsEslint(tree)).toBe(true); | ||
}); | ||
|
||
it('should return true when calling containsEslint with a .eslintrc.js config', () => { | ||
tree.write('.eslintrc.js', '{}'); | ||
expect(containsEslint(tree)).toBe(true); | ||
}); | ||
|
||
it('should return false when calling containsEslint witn an incorrect eslint file name', () => { | ||
tree.write('.eslintrc.yaml', '{}'); | ||
expect(containsEslint(tree)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('findEslintFile', () => { | ||
it('should return default name when calling findEslintFile when no eslint is found', () => { | ||
expect(findEslintFile(tree)).toBe('eslintrc.json'); | ||
}); | ||
|
||
it('should return the name of the eslint config when calling findEslintFile', () => { | ||
tree.write('.eslintrc.json', '{}'); | ||
expect(findEslintFile(tree)).toBe('.eslintrc.json'); | ||
}); | ||
|
||
it('should return the name of the eslint config when calling findEslintFile', () => { | ||
tree.write('.eslintrc.js', '{}'); | ||
expect(findEslintFile(tree)).toBe('.eslintrc.js'); | ||
}); | ||
|
||
it('should return default name when calling findEslintFile when no eslint is found', () => { | ||
tree.write('.eslintrc.yaml', '{}'); | ||
|
||
expect(findEslintFile(tree)).toBe('eslintrc.json'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
|
||
const eslintFileList = ['.eslintrc.json', '.eslintrc.js']; | ||
|
||
export function containsEslint(tree: Tree): boolean { | ||
for (const file of eslintFileList) { | ||
if (tree.exists(file)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
export function findEslintFile(tree: Tree): string { | ||
for (const file of eslintFileList) { | ||
if (tree.exists(file)) { | ||
return file; | ||
} | ||
} | ||
// Default file | ||
return 'eslintrc.json'; | ||
} |