mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +08:00
fix(@schematics/angular): linting errors in AST utils spec
This commit is contained in:
parent
86f1884e65
commit
94ca819656
@ -16,8 +16,8 @@ import {
|
|||||||
addExportToModule,
|
addExportToModule,
|
||||||
addProviderToModule,
|
addProviderToModule,
|
||||||
addSymbolToNgModuleMetadata,
|
addSymbolToNgModuleMetadata,
|
||||||
insertAfterLastOccurrence,
|
|
||||||
findNodes,
|
findNodes,
|
||||||
|
insertAfterLastOccurrence,
|
||||||
} from './ast-utils';
|
} from './ast-utils';
|
||||||
|
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ function applyChanges(path: string, content: string, changes: Change[]): string
|
|||||||
return getFileContent(tree, path);
|
return getFileContent(tree, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-big-function
|
||||||
describe('ast utils', () => {
|
describe('ast utils', () => {
|
||||||
let modulePath: string;
|
let modulePath: string;
|
||||||
let moduleContent: string;
|
let moduleContent: string;
|
||||||
@ -209,20 +210,23 @@ describe('ast utils', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('insertAfterLastOccurrence', () => {
|
describe('insertAfterLastOccurrence', () => {
|
||||||
const filePath: string = './src/foo.ts';
|
const filePath = './src/foo.ts';
|
||||||
|
|
||||||
it('should work for the default scenario', () => {
|
it('should work for the default scenario', () => {
|
||||||
const fileContent = `const arr = ['foo'];`;
|
const fileContent = `const arr = ['foo'];`;
|
||||||
const source = getTsSource(filePath, fileContent);
|
const source = getTsSource(filePath, fileContent);
|
||||||
const arrayNode = findNodes(source.getChildren().shift() as ts.Node, ts.SyntaxKind.ArrayLiteralExpression);
|
const arrayNode = findNodes(
|
||||||
|
source.getChildren().shift() as ts.Node,
|
||||||
|
ts.SyntaxKind.ArrayLiteralExpression,
|
||||||
|
);
|
||||||
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
||||||
|
|
||||||
const change = insertAfterLastOccurrence(
|
const change = insertAfterLastOccurrence(
|
||||||
elements as any as ts.Node[],
|
elements as unknown as ts.Node[],
|
||||||
`, 'bar'`,
|
`, 'bar'`,
|
||||||
filePath,
|
filePath,
|
||||||
elements.pos,
|
elements.pos,
|
||||||
ts.SyntaxKind.StringLiteral
|
ts.SyntaxKind.StringLiteral,
|
||||||
);
|
);
|
||||||
const output = applyChanges(filePath, fileContent, [change]);
|
const output = applyChanges(filePath, fileContent, [change]);
|
||||||
|
|
||||||
@ -233,15 +237,18 @@ describe('ast utils', () => {
|
|||||||
it('should work without occurrences', () => {
|
it('should work without occurrences', () => {
|
||||||
const fileContent = `const arr = [];`;
|
const fileContent = `const arr = [];`;
|
||||||
const source = getTsSource(filePath, fileContent);
|
const source = getTsSource(filePath, fileContent);
|
||||||
const arrayNode = findNodes(source.getChildren().shift() as ts.Node, ts.SyntaxKind.ArrayLiteralExpression);
|
const arrayNode = findNodes(
|
||||||
|
source.getChildren().shift() as ts.Node,
|
||||||
|
ts.SyntaxKind.ArrayLiteralExpression,
|
||||||
|
);
|
||||||
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
||||||
|
|
||||||
const change = insertAfterLastOccurrence(
|
const change = insertAfterLastOccurrence(
|
||||||
elements as any as ts.Node[],
|
elements as unknown as ts.Node[],
|
||||||
`'bar'`,
|
`'bar'`,
|
||||||
filePath,
|
filePath,
|
||||||
elements.pos,
|
elements.pos,
|
||||||
ts.SyntaxKind.StringLiteral
|
ts.SyntaxKind.StringLiteral,
|
||||||
);
|
);
|
||||||
const output = applyChanges(filePath, fileContent, [change]);
|
const output = applyChanges(filePath, fileContent, [change]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user