Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): keep dependency-checks enabled for buildable libraries #19047

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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