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

feat(angular): eslint config including template linting #3988

Merged
merged 14 commits into from
Nov 25, 2020
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
81 changes: 80 additions & 1 deletion e2e/angular/src/angular-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Angular Package', () => {
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support eslint', async () => {
it('should support eslint and pass linting on the standard generated code', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --linter=eslint`);
expect(runCLI(`lint ${myapp}`)).toContain('All files pass linting.');
Expand All @@ -125,4 +125,83 @@ describe('Angular Package', () => {
runCLI(`generate @nrwl/angular:lib ${mylib} --linter=eslint`);
expect(runCLI(`lint ${mylib}`)).toContain('All files pass linting.');
});

it('should support eslint and successfully lint external HTML files and inline templates', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --linter=eslint`);

const templateWhichFailsBananaInBoxLintCheck = `<div ([foo])="bar"></div>`;
const wrappedAsInlineTemplate = `
import { Component } from '@angular/core';

@Component({
selector: 'inline-template-component',
template: \`
${templateWhichFailsBananaInBoxLintCheck}
\`,
})
export class InlineTemplateComponent {}
`;

// External HTML template file
updateFile(
`apps/${myapp}/src/app/app.component.html`,
templateWhichFailsBananaInBoxLintCheck
);

// Inline template within component.ts file
updateFile(
`apps/${myapp}/src/app/inline-template.component.ts`,
wrappedAsInlineTemplate
);

const appLintStdOut = runCLI(`lint ${myapp}`, { silenceError: true });

expect(appLintStdOut).toContain(`apps/${myapp}/src/app/app.component.html`);
expect(appLintStdOut).toContain(
`1:6 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box`
);
expect(appLintStdOut).toContain(
`apps/${myapp}/src/app/inline-template.component.ts`
);
expect(appLintStdOut).toContain(
`5:21 error The selector should be prefixed by one of the prefixes: 'proj' (https://angular.io/guide/styleguide#style-02-07) @angular-eslint/component-selector`
);
expect(appLintStdOut).toContain(
`7:18 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box`
);

const mylib = uniq('mylib');
runCLI(`generate @nrwl/angular:lib ${mylib} --linter=eslint`);

// External HTML template file
updateFile(
`libs/${mylib}/src/lib/some.component.html`,
templateWhichFailsBananaInBoxLintCheck
);

// Inline template within component.ts file
updateFile(
`libs/${mylib}/src/lib/inline-template.component.ts`,
wrappedAsInlineTemplate
);

const libLintStdOut = runCLI(`lint ${mylib}`, { silenceError: true });

expect(libLintStdOut).toContain(
`libs/${mylib}/src/lib/some.component.html`
);
expect(libLintStdOut).toContain(
`1:6 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box`
);
expect(libLintStdOut).toContain(
`libs/${mylib}/src/lib/inline-template.component.ts`
);
expect(libLintStdOut).toContain(
`5:21 error The selector should be prefixed by one of the prefixes: 'proj' (https://angular.io/guide/styleguide#style-02-07) @angular-eslint/component-selector`
);
expect(libLintStdOut).toContain(
`7:18 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box`
);
});
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"@angular-devkit/build-webpack": "~0.1001.3",
"@angular-devkit/core": "~10.1.3",
"@angular-devkit/schematics": "~10.1.3",
"@angular-eslint/eslint-plugin": "0.8.0-beta.1",
"@angular-eslint/eslint-plugin-template": "0.8.0-beta.1",
"@angular-eslint/template-parser": "0.8.0-beta.1",
"@angular/cli": "~10.1.3",
"@angular/common": "~10.1.0",
"@angular/compiler": "~10.1.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"version": "10.4.0-beta.3",
"description": "Adjust karma and protractor setup",
"factory": "./src/migrations/update-10-4-0/update-10-4-0"
},
"add-template-support-and-presets-to-eslint": {
"version": "10.5.0-beta.0",
"description": "Update eslint config and builder to extend from new Nx Angular presets and lint templates",
"factory": "./src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint"
}
},
"packageJsonUpdates": {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"whitelistedNonPeerDependencies": [
"@nrwl/",
"@angular-devkit",
"@angular-eslint/",
"@schematics",
"jasmine-marbles"
]
Expand Down
5 changes: 4 additions & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
"migrations": "./migrations.json"
},
"peerDependencies": {
"@angular-eslint/eslint-plugin": "*",
"@angular-eslint/eslint-plugin-template": "*",
"@angular-eslint/template-parser": "*",
"@nrwl/workspace": "*"
},
"dependencies": {
"@angular-devkit/schematics": "~10.1.3",
"@nrwl/cypress": "*",
"@nrwl/jest": "*",
"@nrwl/linter": "*",
"@angular-devkit/schematics": "~10.1.3",
"@schematics/angular": "~10.1.3",
"jasmine-marbles": "~0.6.0"
}
Expand Down
Loading