-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eslint-plugin-template): fix fixer of inline templates (#1472)
- Loading branch information
1 parent
592e005
commit 470e12b
Showing
6 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "integration-tests-suite-4", | ||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
"type": "library", | ||
"targets": { | ||
"integration-test": { | ||
"executor": "@angular-eslint/nx-plugin:integration-test-suite", | ||
"options": { | ||
"cwd": "packages/integration-tests", | ||
"testFilePath": "tests/inline-template-fixer.test.ts" | ||
} | ||
} | ||
}, | ||
"implicitDependencies": [ | ||
"integration-tests", | ||
"builder", | ||
"bundled-angular-compiler", | ||
"eslint-plugin", | ||
"eslint-plugin-template", | ||
"schematics", | ||
"template-parser", | ||
"utils" | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/integration-tests/tests/__snapshots__/inline-template-fixer.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`inline-template-fixer should generate the expected inline template fixer result 1`] = ` | ||
" | ||
import { Component } from '@angular/core'; | ||
@Component({ | ||
template: \` | ||
<div></div> <!-- no autofocus --> | ||
{{ '' }} <!-- no-distracting-elements --> | ||
<div></div> <!-- table-scope --> | ||
\` | ||
}) | ||
export class TestComponent {} | ||
" | ||
`; |
51 changes: 51 additions & 0 deletions
51
packages/integration-tests/tests/inline-template-fixer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
FIXTURES_DIR, | ||
LONG_TIMEOUT_MS, | ||
runNgAdd, | ||
runNgNew, | ||
} from '../utils/local-registry-process'; | ||
import path from 'path'; | ||
import { setWorkspaceRoot, workspaceRoot } from 'nx/src/utils/workspace-root'; | ||
import fs from 'fs'; | ||
import { runLintFix } from '../utils/run-lint'; | ||
|
||
const fixtureDirectory = 'inline-template-fixer'; | ||
|
||
const inlineTemplateFileContent = ` | ||
import { Component } from '@angular/core'; | ||
@Component({ | ||
template: \` | ||
<div autofocus></div> <!-- no autofocus --> | ||
<marquee></marquee>{{ '' }} <!-- no-distracting-elements --> | ||
<div scope></div> <!-- table-scope --> | ||
\` | ||
}) | ||
export class TestComponent {} | ||
`; | ||
|
||
describe(fixtureDirectory, () => { | ||
jest.setTimeout(LONG_TIMEOUT_MS); | ||
|
||
beforeEach(async () => { | ||
process.chdir(FIXTURES_DIR); | ||
await runNgNew(fixtureDirectory); | ||
process.env.NX_DAEMON = 'false'; | ||
process.env.NX_CACHE_PROJECT_GRAPH = 'false'; | ||
|
||
const workspaceRoot = path.join(FIXTURES_DIR, fixtureDirectory); | ||
process.chdir(workspaceRoot); | ||
process.env.NX_WORKSPACE_ROOT_PATH = workspaceRoot; | ||
setWorkspaceRoot(workspaceRoot); | ||
|
||
await runNgAdd(); | ||
}); | ||
|
||
it('should generate the expected inline template fixer result', async () => { | ||
const testFilePath = path.join(workspaceRoot, 'src', 'test.component.ts'); | ||
fs.writeFileSync(testFilePath, inlineTemplateFileContent); | ||
await runLintFix(fixtureDirectory); | ||
const fileContent = fs.readFileSync(testFilePath, 'utf8'); | ||
expect(fileContent).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters