Skip to content

Commit

Permalink
fix(angular): buildable libs should lint correctly #18802
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Aug 25, 2023
1 parent b9eba9d commit b895ea0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/angular/src/generators/add-linting/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { versions } from '../../utils/version-utils';

export function addAngularEsLintDependencies(tree: Tree): GeneratorCallback {
const angularEslintVersionToInstall = versions(tree).angularEslintVersion;
const jsoncEslintParserVersionToInstall =
versions(tree).jsoncEslintParserVersion;
return addDependenciesToPackageJson(
tree,
{},
{
'@angular-eslint/eslint-plugin': angularEslintVersionToInstall,
'@angular-eslint/eslint-plugin-template': angularEslintVersionToInstall,
'@angular-eslint/template-parser': angularEslintVersionToInstall,
'jsonc-eslint-parser': jsoncEslintParserVersionToInstall,
}
);
}
46 changes: 46 additions & 0 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,52 @@ describe('lib', () => {
expect(tree.exists(path)).toBeTruthy();
});

expect(tree.read('my-dir/my-lib/.eslintrc.json', 'utf-8'))
.toMatchInlineSnapshot(`
"{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {}
},
{
"files": ["*.ts"],
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "proj",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "proj",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
"
`);

// Make sure these have properties
[
{
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/utils/backward-compatible-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const backwardCompatibleVersions: Record<
jestPresetAngularVersion: '~12.2.3',
typesNodeVersion: '16.11.7',
jasmineMarblesVersion: '^0.9.2',
jsoncEslintParserVersion: '^2.1.0',
},
angularV15: {
angularVersion: '~15.2.0',
Expand Down Expand Up @@ -64,5 +65,6 @@ export const backwardCompatibleVersions: Record<
jestPresetAngularVersion: '~13.0.0',
typesNodeVersion: '16.11.7',
jasmineMarblesVersion: '^0.9.2',
jsoncEslintParserVersion: '^2.1.0',
},
};
2 changes: 2 additions & 0 deletions packages/angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const tsNodeVersion = '10.9.1';
export const jestPresetAngularVersion = '~13.1.0';
export const typesNodeVersion = '16.11.7';
export const jasmineMarblesVersion = '^0.9.2';

export const jsoncEslintParserVersion = '^2.1.0';

0 comments on commit b895ea0

Please sign in to comment.