Skip to content

Commit

Permalink
fix(angular): keep dependency-checks enabled for buildable libraries (#…
Browse files Browse the repository at this point in the history
…19047)

(cherry picked from commit bcb5965)
  • Loading branch information
meeroslav authored and FrozenPandaz committed Sep 7, 2023
1 parent 143b223 commit 58b13a2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
26 changes: 21 additions & 5 deletions packages/angular/src/generators/add-linting/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
formatFiles,
GeneratorCallback,
joinPathFragments,
readProjectConfiguration,
runTasksInSerial,
Tree,
} from '@nx/devkit';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
]
: []),
]);
}

Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,6 @@ describe('app', () => {
"!**/*",
],
"overrides": [
{
"files": [
"*.json",
],
"parser": "jsonc-eslint-parser",
"rules": {},
},
{
"extends": [
"plugin:@nx/angular",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
78 changes: 71 additions & 7 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,6 @@ describe('lib', () => {
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {}
},
{
"files": ["*.ts"],
"extends": [
Expand Down Expand Up @@ -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"
}
}
]
}
Expand Down Expand Up @@ -1158,12 +1160,65 @@ describe('lib', () => {
],
"overrides": [
{
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates",
],
"files": [
"*.json",
"*.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",
Expand Down Expand Up @@ -1200,6 +1255,15 @@ describe('lib', () => {
],
"rules": {},
},
{
"files": [
"*.json",
],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error",
},
},
],
}
`);
Expand Down

0 comments on commit 58b13a2

Please sign in to comment.