fix(angular): use build-angular for linting
This commit is contained in:
parent
cdcab0107c
commit
aecdd2bc4c
@ -369,7 +369,7 @@ export default function(schema: Schema): Rule {
|
||||
...options,
|
||||
skipFormat: true
|
||||
}),
|
||||
addLintFiles(options.appProjectRoot, 'tslint', true),
|
||||
addLintFiles(options.appProjectRoot, options.linter, true),
|
||||
externalSchematic('@schematics/angular', 'application', {
|
||||
name: options.name,
|
||||
inlineStyle: options.inlineStyle,
|
||||
@ -394,7 +394,8 @@ export default function(schema: Schema): Rule {
|
||||
? externalSchematic('@nrwl/cypress', 'cypress-project', {
|
||||
name: options.e2eProjectName,
|
||||
directory: options.directory,
|
||||
project: options.name
|
||||
project: options.name,
|
||||
linter: options.linter
|
||||
})
|
||||
: noop(),
|
||||
move(appProjectRoot, options.appProjectRoot),
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { E2eTestRunner } from '../../utils/test-runners';
|
||||
import { UnitTestRunner } from '../../utils/UnitTestRunner';
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
@ -14,7 +15,7 @@ export interface Schema {
|
||||
skipTests?: boolean;
|
||||
directory?: string;
|
||||
tags?: string;
|
||||
linter: string;
|
||||
linter: Linter;
|
||||
unitTestRunner: UnitTestRunner;
|
||||
e2eTestRunner: E2eTestRunner;
|
||||
}
|
||||
|
||||
@ -1,38 +1,41 @@
|
||||
import { join, normalize } from '@angular-devkit/core';
|
||||
import {
|
||||
apply,
|
||||
chain,
|
||||
externalSchematic,
|
||||
noop,
|
||||
Rule,
|
||||
Tree,
|
||||
SchematicContext,
|
||||
schematic,
|
||||
url,
|
||||
apply,
|
||||
MergeStrategy,
|
||||
mergeWith,
|
||||
move,
|
||||
noop,
|
||||
Rule,
|
||||
schematic,
|
||||
SchematicContext,
|
||||
template,
|
||||
MergeStrategy
|
||||
Tree,
|
||||
url
|
||||
} from '@angular-devkit/schematics';
|
||||
import { Schema } from './schema';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {
|
||||
NxJson,
|
||||
updateJsonInTree,
|
||||
readJsonInTree,
|
||||
offsetFromRoot,
|
||||
addLintFiles
|
||||
} from '@nrwl/workspace';
|
||||
import { addGlobal, addIncludeToTsConfig, insert } from '@nrwl/workspace';
|
||||
import { toClassName, toFileName, toPropertyName } from '@nrwl/workspace';
|
||||
import {
|
||||
addGlobal,
|
||||
addIncludeToTsConfig,
|
||||
addLintFiles,
|
||||
formatFiles,
|
||||
getNpmScope,
|
||||
getWorkspacePath,
|
||||
replaceAppNameWithPath
|
||||
insert,
|
||||
Linter,
|
||||
NxJson,
|
||||
offsetFromRoot,
|
||||
readJsonInTree,
|
||||
replaceAppNameWithPath,
|
||||
toClassName,
|
||||
toFileName,
|
||||
toPropertyName,
|
||||
updateJsonInTree
|
||||
} from '@nrwl/workspace';
|
||||
import { formatFiles } from '@nrwl/workspace';
|
||||
import { addUnitTestRunner } from '../ng-add/ng-add';
|
||||
import { addImportToModule, addRoute } from '../../utils/ast-utils';
|
||||
import { insertImport } from '@nrwl/workspace/src/utils/ast-utils';
|
||||
@ -431,7 +434,7 @@ export default function(schema: Schema): Rule {
|
||||
}
|
||||
|
||||
return chain([
|
||||
addLintFiles(options.projectRoot, 'tslint', true),
|
||||
addLintFiles(options.projectRoot, Linter.TsLint, true),
|
||||
addUnitTestRunner(options),
|
||||
externalSchematic('@schematics/angular', 'library', {
|
||||
name: options.name,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { UnitTestRunner } from '../../utils/test-runners';
|
||||
import { Framework } from '../../utils/framework';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { Tree } from '@angular-devkit/schematics';
|
||||
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
|
||||
import { runSchematic } from '../../utils/testing';
|
||||
import { readJsonInTree } from '@nrwl/workspace';
|
||||
import { join, normalize } from '@angular-devkit/core';
|
||||
import { readJsonInTree, Linter } from '@nrwl/workspace';
|
||||
|
||||
describe('schematic:cypress-project', () => {
|
||||
let appTree: Tree;
|
||||
@ -40,7 +39,7 @@ describe('schematic:cypress-project', () => {
|
||||
it('should add update `workspace.json` file', async () => {
|
||||
const tree = await runSchematic(
|
||||
'cypress-project',
|
||||
{ name: 'my-app-e2e', project: 'my-app' },
|
||||
{ name: 'my-app-e2e', project: 'my-app', linter: Linter.TsLint },
|
||||
appTree
|
||||
);
|
||||
const workspaceJson = readJsonInTree(tree, 'workspace.json');
|
||||
@ -49,9 +48,8 @@ describe('schematic:cypress-project', () => {
|
||||
expect(project.root).toEqual('apps/my-app-e2e');
|
||||
|
||||
expect(project.architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: ['apps/my-app-e2e/tsconfig.e2e.json'],
|
||||
exclude: ['**/node_modules/**', '!apps/my-app-e2e/**']
|
||||
}
|
||||
@ -71,6 +69,26 @@ describe('schematic:cypress-project', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add update `workspace.json` file properly when eslint is passed', async () => {
|
||||
const tree = await runSchematic(
|
||||
'cypress-project',
|
||||
{ name: 'my-app-e2e', project: 'my-app', linter: Linter.EsLint },
|
||||
appTree
|
||||
);
|
||||
const workspaceJson = readJsonInTree(tree, 'workspace.json');
|
||||
const project = workspaceJson.projects['my-app-e2e'];
|
||||
|
||||
expect(project.architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
options: {
|
||||
linter: 'eslint',
|
||||
config: 'apps/my-app-e2e/.eslintrc',
|
||||
tsConfig: ['apps/my-app-e2e/tsconfig.e2e.json'],
|
||||
exclude: ['**/node_modules/**', '!apps/my-app-e2e/**']
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should set right path names in `cypress.json`', async () => {
|
||||
const tree = await runSchematic(
|
||||
'cypress-project',
|
||||
@ -111,7 +129,12 @@ describe('schematic:cypress-project', () => {
|
||||
it('should update workspace.json', async () => {
|
||||
const tree = await runSchematic(
|
||||
'cypress-project',
|
||||
{ name: 'my-app-e2e', project: 'my-dir-my-app', directory: 'my-dir' },
|
||||
{
|
||||
name: 'my-app-e2e',
|
||||
project: 'my-dir-my-app',
|
||||
directory: 'my-dir',
|
||||
linter: Linter.TsLint
|
||||
},
|
||||
appTree
|
||||
);
|
||||
const projectConfig = readJsonInTree(tree, 'workspace.json').projects[
|
||||
@ -120,9 +143,8 @@ describe('schematic:cypress-project', () => {
|
||||
|
||||
expect(projectConfig).toBeDefined();
|
||||
expect(projectConfig.architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: ['apps/my-dir/my-app-e2e/tsconfig.e2e.json'],
|
||||
exclude: ['**/node_modules/**', '!apps/my-dir/my-app-e2e/**']
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
project: string;
|
||||
name: string;
|
||||
directory: string;
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { UnitTestRunner } from '../../utils/test-runners';
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
skipFormat: boolean;
|
||||
@ -6,6 +8,6 @@ export interface Schema {
|
||||
directory?: string;
|
||||
unitTestRunner: UnitTestRunner;
|
||||
tags?: string;
|
||||
linter: string;
|
||||
linter: Linter;
|
||||
frontendProject?: string;
|
||||
}
|
||||
|
||||
@ -15,9 +15,8 @@ describe('jestProject', () => {
|
||||
root: 'libs/lib1',
|
||||
architect: {
|
||||
lint: {
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: []
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { UnitTestRunner } from '../../utils/test-runners';
|
||||
import { Linter } from 'tslint';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
skipFormat: boolean;
|
||||
@ -6,6 +8,6 @@ export interface Schema {
|
||||
directory?: string;
|
||||
unitTestRunner: UnitTestRunner;
|
||||
tags?: string;
|
||||
linter: string;
|
||||
linter: Linter;
|
||||
frontendProject?: string;
|
||||
}
|
||||
|
||||
@ -53,9 +53,8 @@ describe('app', () => {
|
||||
})
|
||||
);
|
||||
expect(workspaceJson.projects['my-node-app'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: [
|
||||
'apps/my-node-app/tsconfig.app.json',
|
||||
'apps/my-node-app/tsconfig.spec.json'
|
||||
@ -125,9 +124,8 @@ describe('app', () => {
|
||||
expect(
|
||||
workspaceJson.projects['my-dir-my-node-app'].architect.lint
|
||||
).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: [
|
||||
'apps/my-dir/my-node-app/tsconfig.app.json',
|
||||
'apps/my-dir/my-node-app/tsconfig.spec.json'
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
skipFormat: boolean;
|
||||
skipPackageJson: boolean;
|
||||
directory?: string;
|
||||
unitTestRunner: 'jest' | 'none';
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
tags?: string;
|
||||
frontendProject?: string;
|
||||
}
|
||||
|
||||
@ -292,9 +292,8 @@ describe('app', () => {
|
||||
);
|
||||
const workspaceJson = readJsonInTree(tree, 'workspace.json');
|
||||
expect(workspaceJson.projects['my-app'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!apps/my-app/**'],
|
||||
tsConfig: [
|
||||
'apps/my-app/tsconfig.app.json',
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
style?: string;
|
||||
@ -6,7 +8,7 @@ export interface Schema {
|
||||
tags?: string;
|
||||
unitTestRunner: 'jest' | 'none';
|
||||
e2eTestRunner: 'cypress' | 'none';
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
pascalCaseFiles?: boolean;
|
||||
classComponent?: boolean;
|
||||
routing?: boolean;
|
||||
|
||||
@ -19,9 +19,8 @@ describe('lib', () => {
|
||||
expect(workspaceJson.projects['my-lib'].root).toEqual('libs/my-lib');
|
||||
expect(workspaceJson.projects['my-lib'].architect.build).toBeUndefined();
|
||||
expect(workspaceJson.projects['my-lib'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!libs/my-lib/**'],
|
||||
tsConfig: [
|
||||
'libs/my-lib/tsconfig.lib.json',
|
||||
@ -184,9 +183,8 @@ describe('lib', () => {
|
||||
'libs/my-dir/my-lib'
|
||||
);
|
||||
expect(workspaceJson.projects['my-dir-my-lib'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!libs/my-dir/my-lib/**'],
|
||||
tsConfig: [
|
||||
'libs/my-dir/my-lib/tsconfig.lib.json',
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { Linter } from '@nrwl/workspace';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
directory?: string;
|
||||
@ -10,5 +12,5 @@ export interface Schema {
|
||||
routing?: boolean;
|
||||
parentRoute?: string;
|
||||
unitTestRunner: 'jest' | 'none';
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
}
|
||||
|
||||
@ -284,9 +284,8 @@ describe('app', () => {
|
||||
const workspaceJson = readJsonInTree(tree, 'workspace.json');
|
||||
|
||||
expect(workspaceJson.projects['my-app'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!apps/my-app/**'],
|
||||
tsConfig: [
|
||||
'apps/my-app/tsconfig.app.json',
|
||||
|
||||
@ -7,5 +7,5 @@ export interface Schema {
|
||||
tags?: string;
|
||||
unitTestRunner: 'jest' | 'none';
|
||||
e2eTestRunner: 'cypress' | 'none';
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ export {
|
||||
|
||||
export { getWorkspace, updateWorkspace } from './src/utils/workspace';
|
||||
export { addUpdateTask } from './src/utils/update-task';
|
||||
export { addLintFiles, generateProjectLint } from './src/utils/lint';
|
||||
export { addLintFiles, generateProjectLint, Linter } from './src/utils/lint';
|
||||
|
||||
export { formatFiles } from './src/utils/rules/format-files';
|
||||
export { deleteFile } from './src/utils/rules/deleteFile';
|
||||
|
||||
@ -20,9 +20,8 @@ describe('lib', () => {
|
||||
expect(workspaceJson.projects['my-lib'].root).toEqual('libs/my-lib');
|
||||
expect(workspaceJson.projects['my-lib'].architect.build).toBeUndefined();
|
||||
expect(workspaceJson.projects['my-lib'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!libs/my-lib/**'],
|
||||
tsConfig: [
|
||||
'libs/my-lib/tsconfig.lib.json',
|
||||
@ -167,9 +166,8 @@ describe('lib', () => {
|
||||
'libs/my-dir/my-lib'
|
||||
);
|
||||
expect(workspaceJson.projects['my-dir-my-lib'].architect.lint).toEqual({
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
exclude: ['**/node_modules/**', '!libs/my-dir/my-lib/**'],
|
||||
tsConfig: [
|
||||
'libs/my-dir/my-lib/tsconfig.lib.json',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { UnitTestRunner } from '../../utils/test-runners';
|
||||
import { Linter } from '@nrwl/workspace/src/utils/lint';
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
@ -8,5 +8,5 @@ export interface Schema {
|
||||
tags?: string;
|
||||
simpleModuleName: boolean;
|
||||
unitTestRunner: 'jest' | 'none';
|
||||
linter: 'eslint' | 'tslint';
|
||||
linter: Linter;
|
||||
}
|
||||
|
||||
@ -13,21 +13,26 @@ import {
|
||||
eslintConfigPrettierVersion
|
||||
} from './versions';
|
||||
|
||||
export const enum Linter {
|
||||
TsLint = 'tslint',
|
||||
EsLint = 'eslint',
|
||||
None = 'none'
|
||||
}
|
||||
|
||||
export function generateProjectLint(
|
||||
projectRoot: string,
|
||||
tsConfigPath: string,
|
||||
linter: 'tslint' | 'eslint' | 'none'
|
||||
linter: Linter
|
||||
) {
|
||||
if (linter === 'tslint') {
|
||||
if (linter === Linter.TsLint) {
|
||||
return {
|
||||
builder: '@nrwl/linter:lint',
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
linter: 'tslint',
|
||||
tsConfig: [tsConfigPath],
|
||||
exclude: ['**/node_modules/**', '!' + projectRoot + '/**']
|
||||
}
|
||||
};
|
||||
} else if (linter === 'eslint') {
|
||||
} else if (linter === Linter.EsLint) {
|
||||
return {
|
||||
builder: '@nrwl/linter:lint',
|
||||
options: {
|
||||
@ -44,7 +49,7 @@ export function generateProjectLint(
|
||||
|
||||
export function addLintFiles(
|
||||
projectRoot: string,
|
||||
linter: 'tslint' | 'eslint' | 'none',
|
||||
linter: Linter,
|
||||
onlyGlobal = false
|
||||
): Rule {
|
||||
return (host: Tree, context: SchematicContext) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user