Skip to content

Commit

Permalink
feat(@schematics/angular): remove tslint and codelyzer from new projects
Browse files Browse the repository at this point in the history
Both of these projects and the tslint builder are deprecated.

Closes #20105 and closes #18465
  • Loading branch information
alan-agius4 committed Mar 16, 2021
1 parent b6d693f commit 226a8d2
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 210 deletions.
18 changes: 0 additions & 18 deletions packages/schematics/angular/application/files/tslint.json.template

This file was deleted.

38 changes: 1 addition & 37 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { Schema as ComponentOptions } from '../component/schema';
import { Schema as E2eOptions } from '../e2e/schema';
import { NodeDependencyType, addPackageJsonDependency } from '../utility/dependencies';
import { JSONFile } from '../utility/json-file';
import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { relativePathToWorkspaceRoot } from '../utility/paths';
Expand Down Expand Up @@ -68,28 +67,6 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
};
}

/**
* Merges the application tslint.json with the workspace tslint.json
* when the application being created is a root application
*
* @param {Tree} parentHost The root host of the schematic
*/
function mergeWithRootTsLint(parentHost: Tree) {
return (host: Tree) => {
const tsLintPath = '/tslint.json';
const rulesPath = ['rules'];
if (!host.exists(tsLintPath)) {
return;
}

const rootTsLintFile = new JSONFile(parentHost, tsLintPath);
const rootRules = rootTsLintFile.get(rulesPath) as {};
const appRules = new JSONFile(host, tsLintPath).get(rulesPath) as {};
rootTsLintFile.modify(rulesPath, { ...rootRules, ...appRules });
host.overwrite(tsLintPath, rootTsLintFile.content);
};
}

function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rule {
let projectRoot = appDir;
if (projectRoot) {
Expand Down Expand Up @@ -245,18 +222,6 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
scripts: [],
},
},
lint: options.minimal ? undefined : {
builder: Builders.TsLint,
options: {
tsConfig: [
`${projectRoot}tsconfig.app.json`,
`${projectRoot}tsconfig.spec.json`,
],
exclude: [
'**/node_modules/**',
],
},
},
},
};

Expand All @@ -272,7 +237,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
});
}
function minimalPathFilter(path: string): boolean {
const toRemoveList = /(test.ts|tsconfig.spec.json|karma.conf.js|tslint.json).template$/;
const toRemoveList = /(test.ts|tsconfig.spec.json|karma.conf.js).template$/;

return !toRemoveList.test(path);
}
Expand Down Expand Up @@ -327,7 +292,6 @@ export default function (options: ApplicationOptions): Rule {
appName: options.name,
isRootApp,
}),
isRootApp ? mergeWithRootTsLint(host) : noop(),
move(appDir),
]), MergeStrategy.Overwrite),
schematic('module', {
Expand Down
65 changes: 1 addition & 64 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe('Application Schematic', () => {
'/projects/foo/karma.conf.js',
'/projects/foo/tsconfig.app.json',
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/src/environments/environment.ts',
'/projects/foo/src/environments/environment.prod.ts',
'/projects/foo/src/favicon.ico',
Expand Down Expand Up @@ -153,42 +152,21 @@ describe('Application Schematic', () => {
expect(_extends).toBe('../../tsconfig.json');
});

it('should set the right path and prefix in the tslint file', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const path = '/projects/foo/tslint.json';
const content = JSON.parse(tree.readContent(path));
expect(content.extends).toMatch('../../tslint.json');
expect(content.rules['directive-selector'][2]).toMatch('app');
expect(content.rules['component-selector'][2]).toMatch('app');
});

it('should set the right prefix in the tslint file when provided is kebabed', async () => {
const options: ApplicationOptions = { ...defaultOptions, prefix: 'foo-bar' };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const path = '/projects/foo/tslint.json';
const content = JSON.parse(tree.readContent(path));
expect(content.rules['directive-selector'][2]).toMatch('fooBar');
expect(content.rules['component-selector'][2]).toMatch('foo-bar');
});

it('should set the right coverage folder in the karma.json file', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const karmaConf = getFileContent(tree, '/projects/foo/karma.conf.js');
expect(karmaConf).toContain(`dir: require('path').join(__dirname, '../../coverage/foo')`);
});

it('minimal=true should not create e2e, lint and test targets', async () => {
it('minimal=true should not create e2e and test targets', async () => {
const options = { ...defaultOptions, minimal: true };
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const config = JSON.parse(tree.readContent('/angular.json'));
const architect = config.projects.foo.architect;
expect(architect.test).not.toBeDefined();
expect(architect.e2e).not.toBeDefined();
expect(architect.e2e).not.toBeDefined();
});

it('minimal=true should configure the schematics options for components', async () => {
Expand Down Expand Up @@ -235,7 +213,6 @@ describe('Application Schematic', () => {
const files = tree.files;
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.css',
Expand Down Expand Up @@ -264,7 +241,6 @@ describe('Application Schematic', () => {
const files = tree.files;
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.html',
Expand Down Expand Up @@ -293,7 +269,6 @@ describe('Application Schematic', () => {
const files = tree.files;
[
'/projects/foo/tsconfig.spec.json',
'/projects/foo/tslint.json',
'/projects/foo/karma.conf.js',
'/projects/foo/src/test.ts',
'/projects/foo/src/app/app.component.css',
Expand Down Expand Up @@ -355,18 +330,6 @@ describe('Application Schematic', () => {
const packageJson = JSON.parse(tree.readContent('package.json'));
expect(packageJson.devDependencies['@angular-devkit/build-angular']).toBeUndefined();
});

it('should set the lint tsConfig option', async () => {
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
.toPromise();
const workspace = JSON.parse(tree.readContent('/angular.json'));
const lintOptions = workspace.projects.foo.architect.lint.options;
expect(lintOptions.tsConfig).toEqual([
'projects/foo/tsconfig.app.json',
'projects/foo/tsconfig.spec.json',
'projects/foo/e2e/tsconfig.json',
]);
});
});

describe('custom projectRoot', () => {
Expand All @@ -380,7 +343,6 @@ describe('Application Schematic', () => {
'/karma.conf.js',
'/tsconfig.app.json',
'/tsconfig.spec.json',
'/tslint.json',
'/src/environments/environment.ts',
'/src/environments/environment.prod.ts',
'/src/favicon.ico',
Expand Down Expand Up @@ -448,31 +410,6 @@ describe('Application Schematic', () => {
expect(specTsConfig.files).toEqual(['src/test.ts', 'src/polyfills.ts']);
});

it('should set the relative path and prefix in the tslint file', async () => {
const options = { ...defaultOptions, projectRoot: '' };

const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const content = JSON.parse(tree.readContent('/tslint.json'));
expect(content.extends).toMatch('tslint:recommended');
expect(content.rules['directive-selector'][2]).toMatch('app');
expect(content.rules['component-selector'][2]).toMatch('app');
});

it('should merge tslint file', async () => {
const options = { ...defaultOptions, projectRoot: '' };

const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const content = JSON.parse(tree.readContent('/tslint.json'));
expect(content.extends).toMatch('tslint:recommended');
expect(content.rules['component-selector'][2]).toMatch('app');
expect(content.rules['no-console']).toBeDefined();
// codelyzer rules should be after base tslint rules
expect(Object.keys(content.rules).indexOf('component-selector'))
.toBeGreaterThan(Object.keys(content.rules).indexOf('no-console'));
});

it(`should create correct paths when 'newProjectRoot' is blank`, async () => {
const workspaceTree = await schematicRunner.runSchematicAsync('workspace', { ...workspaceOptions, newProjectRoot: '' }).toPromise();
const options = { ...defaultOptions, projectRoot: undefined };
Expand Down
7 changes: 0 additions & 7 deletions packages/schematics/angular/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ export default function (options: E2eOptions): Rule {
},
});

const e2eTsConfig = `${root}/tsconfig.json`;
const lintTarget = project.targets.get('lint');
if (lintTarget && lintTarget.options && Array.isArray(lintTarget.options.tsConfig)) {
lintTarget.options.tsConfig =
lintTarget.options.tsConfig.concat(e2eTsConfig);
}

return chain([
updateWorkspace(workspace),
mergeWith(
Expand Down
17 changes: 0 additions & 17 deletions packages/schematics/angular/library/files/tslint.json.template

This file was deleted.

12 changes: 0 additions & 12 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ function addLibToWorkspaceFile(
karmaConfig: `${projectRoot}/karma.conf.js`,
},
},
lint: {
builder: Builders.TsLint,
options: {
tsConfig: [
`${projectRoot}/tsconfig.lib.json`,
`${projectRoot}/tsconfig.spec.json`,
],
exclude: [
'**/node_modules/**',
],
},
},
},
});
});
Expand Down
19 changes: 0 additions & 19 deletions packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe('Library Schematic', () => {
'/projects/foo/ng-package.json',
'/projects/foo/package.json',
'/projects/foo/README.md',
'/projects/foo/tslint.json',
'/projects/foo/tsconfig.lib.json',
'/projects/foo/tsconfig.lib.prod.json',
'/projects/foo/src/test.ts',
Expand Down Expand Up @@ -126,15 +125,6 @@ describe('Library Schematic', () => {
expect(workspace.projects.foo.prefix).toEqual('pre');
});

it('should set the right prefix in the tslint file when provided is kebabed', async () => {
const options: GenerateLibrarySchema = { ...defaultOptions, prefix: 'foo-bar' };
const tree = await schematicRunner.runSchematicAsync('library', options, workspaceTree).toPromise();
const path = '/projects/foo/tslint.json';
const content = JSON.parse(tree.readContent(path));
expect(content.rules['directive-selector'][2]).toMatch('fooBar');
expect(content.rules['component-selector'][2]).toMatch('foo-bar');
});

it('should handle a pascalCasedName', async () => {
const options = { ...defaultOptions, name: 'pascalCasedName' };
const tree = await schematicRunner.runSchematicAsync('library', options, workspaceTree).toPromise();
Expand All @@ -152,15 +142,6 @@ describe('Library Schematic', () => {
expect(fileContent).toContain('exports: [FooComponent]');
});

it('should set the right path and prefix in the tslint file', async () => {
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree).toPromise();
const path = '/projects/foo/tslint.json';
const content = JSON.parse(tree.readContent(path));
expect(content.extends).toMatch('../../tslint.json');
expect(content.rules['directive-selector'][2]).toMatch('lib');
expect(content.rules['component-selector'][2]).toMatch('lib');
});

describe(`update package.json`, () => {
it(`should add ng-packagr to devDependencies`, async () => {
const tree = await schematicRunner.runSchematicAsync('library', defaultOptions, workspaceTree).toPromise();
Expand Down
5 changes: 0 additions & 5 deletions packages/schematics/angular/universal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
},
configurations,
});

const lintTarget = clientProject.targets.get('lint');
if (lintTarget && lintTarget.options && Array.isArray(lintTarget.options.tsConfig)) {
lintTarget.options.tsConfig = lintTarget.options.tsConfig.concat(serverTsConfig);
}
}
});
}
Expand Down
7 changes: 0 additions & 7 deletions packages/schematics/angular/utility/workspace-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ export interface TestBuilderOptions extends Partial<BrowserBuilderBaseOptions> {
karmaConfig: string;
}

export interface LintBuilderOptions {
tsConfig: string[] | string;
exclude?: string[];
}

export interface ExtractI18nOptions {
browserTarget: string;
}
Expand All @@ -125,7 +120,6 @@ export type LibraryBuilderTarget = BuilderTarget<Builders.NgPackagr, LibraryBuil
export type BrowserBuilderTarget = BuilderTarget<Builders.Browser, BrowserBuilderOptions>;
export type ServerBuilderTarget = BuilderTarget<Builders.Server, ServerBuilderOptions>;
export type AppShellBuilderTarget = BuilderTarget<Builders.AppShell, AppShellBuilderOptions>;
export type LintBuilderTarget = BuilderTarget<Builders.TsLint, LintBuilderOptions>;
export type TestBuilderTarget = BuilderTarget<Builders.Karma, TestBuilderOptions>;
export type ServeBuilderTarget = BuilderTarget<Builders.DevServer, ServeBuilderOptions>;
export type ExtractI18nBuilderTarget = BuilderTarget<Builders.ExtractI18n, ExtractI18nOptions>;
Expand Down Expand Up @@ -165,7 +159,6 @@ export interface WorkspaceProject<TProjectType extends ProjectType = ProjectType
export interface WorkspaceTargets<TProjectType extends ProjectType = ProjectType.Application> {
build?: TProjectType extends ProjectType.Library ? LibraryBuilderTarget : BrowserBuilderTarget;
server?: ServerBuilderTarget;
lint?: LintBuilderTarget;
test?: TestBuilderTarget;
serve?: ServeBuilderTarget;
e2e?: E2EBuilderTarget;
Expand Down
9 changes: 1 addition & 8 deletions packages/schematics/angular/web-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { JSONFile } from '../utility/json-file';
import { parseName } from '../utility/parse-name';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { buildDefaultPath, getWorkspace, updateWorkspace } from '../utility/workspace';
import { BrowserBuilderOptions, LintBuilderOptions } from '../utility/workspace-models';
import { BrowserBuilderOptions } from '../utility/workspace-models';
import { Schema as WebWorkerOptions } from './schema';


Expand Down Expand Up @@ -135,13 +135,6 @@ export default function (options: WebWorkerOptions): Rule {
if (needWebWorkerConfig) {
const workerConfigPath = join(normalize(root), 'tsconfig.worker.json');
projectTargetOptions.webWorkerTsConfig = workerConfigPath;

// add worker tsconfig to lint architect target
const lintTarget = project.targets.get('lint');
if (lintTarget) {
const lintOptions = (lintTarget.options || {}) as unknown as LintBuilderOptions;
lintOptions.tsConfig = (lintOptions.tsConfig || []).concat(workerConfigPath);
}
}

const templateSource = apply(url('./files/worker'), [
Expand Down
Loading

0 comments on commit 226a8d2

Please sign in to comment.