-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): renamed exported recommended (#2354)
## Proposed change feat(eslint-plugin): renamed exported recommended fix(eslint-plugin): turn yaml parser really optional deprecate(eslint-plugin): recommended exports based on types <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that is required for this change. --> ## Related issues - 🚀 Feature resolves #1487 - 🐛 Fix resolves #2482 <!-- Please make sure to follow the contributing guidelines on https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
- Loading branch information
Showing
7 changed files
with
187 additions
and
44 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
43 changes: 43 additions & 0 deletions
43
...@o3r/eslint-config-otter/schematics/ng-update/v11.6/update-configs/update-configs.spec.ts
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,43 @@ | ||
import { | ||
Tree, | ||
} from '@angular-devkit/schematics'; | ||
import { | ||
updateEslintRecommended, | ||
} from './update-configs'; | ||
|
||
let findFilesInTreeFn: () => any[] = () => []; | ||
|
||
jest.mock('@o3r/schematics', () => ({ | ||
findFilesInTree: jest.fn().mockImplementation(() => findFilesInTreeFn()) | ||
})); | ||
|
||
describe('updateEslintRecommended', () => { | ||
beforeEach(() => jest.restoreAllMocks()); | ||
|
||
it('should update configs', async () => { | ||
const initialTree = Tree.empty(); | ||
initialTree.create('random.file', 'a file containing json-recommended'); | ||
initialTree.create('/test/.eslintrc.json', '{ "extends": ["@o3r/json-recommended", "@other/json-recommended"] }'); | ||
findFilesInTreeFn = () => [ | ||
initialTree.get('random.file'), | ||
initialTree.get('/test/.eslintrc.json') | ||
]; | ||
await updateEslintRecommended()(initialTree, null as any); | ||
|
||
expect(initialTree.readText('random.file')).toContain('json-recommended'); | ||
expect(initialTree.readText('/test/.eslintrc.json')).toBe('{ "extends": ["@o3r/monorepo-recommended", "@other/json-recommended"] }'); | ||
}); | ||
|
||
it('should update configs on findFilesInTree failure', async () => { | ||
findFilesInTreeFn = () => { | ||
throw new Error('test'); | ||
}; | ||
const initialTree = Tree.empty(); | ||
initialTree.create('random.file', 'a file containing json-recommended'); | ||
initialTree.create('/test/.eslintrc.json', '{ "extends": ["@o3r/json-recommended", "@other/json-recommended"] }'); | ||
await updateEslintRecommended()(initialTree, null as any); | ||
|
||
expect(initialTree.readText('random.file')).toContain('json-recommended'); | ||
expect(initialTree.readText('/test/.eslintrc.json')).toBe('{ "extends": ["@o3r/monorepo-recommended", "@other/json-recommended"] }'); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
...ages/@o3r/eslint-config-otter/schematics/ng-update/v11.6/update-configs/update-configs.ts
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,44 @@ | ||
import { | ||
basename, | ||
} from 'node:path'; | ||
import type { | ||
FileEntry, | ||
Rule, | ||
} from '@angular-devkit/schematics'; | ||
|
||
/** | ||
* Update Eslint files to new recommended names | ||
*/ | ||
export function updateEslintRecommended(): Rule { | ||
const configFilePattern = /^.?eslint(:?rc)?\..*/; | ||
const toReplace = { | ||
|
||
'angular-template-recommended': /(['"](?:plugin:)?@o3r\/)template-recommended(['"])/g, | ||
|
||
'monorepo-recommended': /(['"](?:plugin:)?@o3r\/)json-recommended(['"])/g | ||
}; | ||
|
||
const isFileToParse = (path: string) => configFilePattern.test(basename(path)); | ||
|
||
return async (tree) => { | ||
let files: FileEntry[]; | ||
try { | ||
const { findFilesInTree } = await import('@o3r/schematics'); | ||
files = findFilesInTree(tree.getDir('/'), isFileToParse); | ||
} catch { | ||
files = []; | ||
tree.visit((path) => isFileToParse(path) && files.push(tree.get(path)!)); | ||
} | ||
|
||
files.forEach(({ content, path }) => { | ||
const contentStr = content.toString(); | ||
const newContent = Object.entries(toReplace).reduce((acc, [rule, regexp]) => { | ||
return acc.replaceAll(regexp, `$1${rule}$2`); | ||
}, contentStr); | ||
|
||
if (contentStr !== newContent) { | ||
tree.overwrite(path, newContent); | ||
} | ||
}); | ||
}; | ||
} |
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