fix(angular): keep dependency-checks enabled for buildable libraries (#19047)
This commit is contained in:
parent
f487929a9e
commit
bcb5965ec5
@ -9,13 +9,6 @@ exports[`addLinting generator should correctly generate the .eslintrc.json file
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
@ -65,13 +58,6 @@ exports[`addLinting generator support angular v14 should correctly generate the
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
|
||||
@ -2,6 +2,7 @@ import {
|
||||
formatFiles,
|
||||
GeneratorCallback,
|
||||
joinPathFragments,
|
||||
readProjectConfiguration,
|
||||
runTasksInSerial,
|
||||
Tree,
|
||||
} from '@nx/devkit';
|
||||
@ -47,11 +48,6 @@ export async function addLintingGenerator(
|
||||
.includes(`${options.projectRoot}/tsconfig.*?.json`);
|
||||
|
||||
replaceOverridesInLintConfig(tree, options.projectRoot, [
|
||||
{
|
||||
files: ['*.json'],
|
||||
parser: 'jsonc-eslint-parser',
|
||||
rules: {},
|
||||
},
|
||||
{
|
||||
files: ['*.ts'],
|
||||
...(hasParserOptions
|
||||
@ -93,6 +89,17 @@ export async function addLintingGenerator(
|
||||
*/
|
||||
rules: {},
|
||||
},
|
||||
...(isBuildableLibraryProject(tree, options.projectName)
|
||||
? [
|
||||
{
|
||||
files: ['*.json'],
|
||||
parser: 'jsonc-eslint-parser',
|
||||
rules: {
|
||||
'@nx/dependency-checks': 'error',
|
||||
} as any,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -108,4 +115,13 @@ export async function addLintingGenerator(
|
||||
return runTasksInSerial(...tasks);
|
||||
}
|
||||
|
||||
function isBuildableLibraryProject(tree: Tree, projectName: string): boolean {
|
||||
const projectConfig = readProjectConfiguration(tree, projectName);
|
||||
return (
|
||||
projectConfig.projectType === 'library' &&
|
||||
projectConfig.targets?.build &&
|
||||
!!projectConfig.targets.build
|
||||
);
|
||||
}
|
||||
|
||||
export default addLintingGenerator;
|
||||
|
||||
@ -512,13 +512,6 @@ describe('app', () => {
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
|
||||
@ -253,13 +253,6 @@ exports[`convert-tslint-to-eslint should not override .eslint config if migratio
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
@ -851,13 +844,6 @@ exports[`convert-tslint-to-eslint should work for Angular applications 4`] = `
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
@ -1211,13 +1197,6 @@ exports[`convert-tslint-to-eslint should work for Angular libraries 4`] = `
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
|
||||
@ -597,11 +597,6 @@ describe('lib', () => {
|
||||
"extends": ["../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.json"],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
@ -631,6 +626,13 @@ describe('lib', () => {
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nx/angular-template"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.json"],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {
|
||||
"@nx/dependency-checks": "error"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1158,12 +1160,65 @@ describe('lib', () => {
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates",
|
||||
],
|
||||
"files": [
|
||||
"*.ts",
|
||||
],
|
||||
"rules": {
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"prefix": "proj",
|
||||
"style": "kebab-case",
|
||||
"type": "element",
|
||||
},
|
||||
],
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"prefix": "proj",
|
||||
"style": "camelCase",
|
||||
"type": "attribute",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular-template",
|
||||
],
|
||||
"files": [
|
||||
"*.html",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should add dependency checks to buildable libs', async () => {
|
||||
// ACT
|
||||
await runLibraryGeneratorWithOpts({
|
||||
linter: Linter.EsLint,
|
||||
buildable: true,
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
|
||||
const eslintConfig = readJson(tree, 'my-lib/.eslintrc.json');
|
||||
expect(eslintConfig).toMatchInlineSnapshot(`
|
||||
{
|
||||
"extends": [
|
||||
"../.eslintrc.json",
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
@ -1200,6 +1255,15 @@ describe('lib', () => {
|
||||
],
|
||||
"rules": {},
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"*.json",
|
||||
],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {
|
||||
"@nx/dependency-checks": "error",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user