@ -17,7 +17,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -31,7 +31,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'dynamic-queries': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -41,7 +41,9 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag dynamic queries', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -172,5 +174,4 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
expect(content).toContain(`@ContentChild('child') set child(c: any) {}`);
|
||||
expect(content).toContain(`@ViewChild('otherChild') set otherChild(c: any) {}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -12,7 +12,6 @@ import * as shx from 'shelljs';
|
||||
import {Configuration, Linter} from 'tslint';
|
||||
|
||||
describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
|
||||
/**
|
||||
* Path to the static-query schematic rules directory. The path needs to be resolved through
|
||||
* the Bazel runfiles, because on Windows runfiles are not symlinked into the working directory.
|
||||
@ -23,7 +22,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -41,7 +40,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'explicit-query-timing': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -32,7 +32,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'no-missing-injectable': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -42,7 +42,9 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
describe('NgModule', () => createTests('NgModule', 'providers'));
|
||||
describe('Directive', () => createTests('Directive', 'providers'));
|
||||
@ -77,7 +79,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
});
|
||||
|
||||
function createTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
it('should create proper failures for missing injectable providers', () => {
|
||||
writeFile('index.ts', `
|
||||
import { ${type} } from '@angular/core';
|
||||
@ -266,6 +268,4 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
.toMatch(/import { Inject, Injectable } from '@angular\/core';/);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -34,7 +34,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
Configuration.parseConfigFile({rules: {'no-template-variable-assignment': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
// We need to declare the Angular symbols we're testing for, otherwise type checking won't work.
|
||||
@ -46,7 +46,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'renderer-to-renderer2': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -56,7 +56,9 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag Renderer imports and typed nodes', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -223,8 +225,8 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
runTSLint(true);
|
||||
const content = getFile('index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g)!.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should insert helpers after the user\'s code', () => {
|
||||
@ -410,5 +412,4 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
// Expect the `setInfo` method to only contain whitespace.
|
||||
expect(content).toMatch(/setInfo\(\) \{\s+\}/);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
});
|
||||
@ -33,7 +33,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -43,7 +43,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag undecorated classes with decorated fields', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -97,8 +99,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`import { Directive, Input } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { HostBinding } from '@angular/core';
|
||||
|
||||
export class Directive {
|
||||
@ -111,12 +114,12 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
}
|
||||
`);
|
||||
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated classes that have @Input', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -250,7 +253,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`@Directive()\nexport class Base {`);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async() => {
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Input, Directive, NgModule } from '@angular/core';
|
||||
|
||||
|
Reference in New Issue
Block a user