refactor: add rule for no unused locals and cleanup
This commit is contained in:
parent
113b51bd33
commit
edac12c859
@ -1,11 +1,4 @@
|
||||
import {
|
||||
newApp,
|
||||
newLib,
|
||||
newProject,
|
||||
runCLI,
|
||||
updateFile,
|
||||
cleanup
|
||||
} from '../utils';
|
||||
import { newApp, newLib, newProject, runCLI, updateFile } from '../utils';
|
||||
|
||||
describe('Nrwl Workspace', () => {
|
||||
it(
|
||||
|
||||
@ -1,11 +1,4 @@
|
||||
import {
|
||||
checkFilesExist,
|
||||
newApp,
|
||||
newBazelProject,
|
||||
newLib,
|
||||
runCLI,
|
||||
updateFile
|
||||
} from '../utils';
|
||||
import { checkFilesExist, newApp, newBazelProject, newLib } from '../utils';
|
||||
|
||||
xdescribe('Nrwl Workspace (Bazel)', () => {
|
||||
it(
|
||||
|
||||
@ -2,7 +2,6 @@ import {
|
||||
newApp,
|
||||
newLib,
|
||||
newProject,
|
||||
readFile,
|
||||
runCLI,
|
||||
runCommand,
|
||||
updateFile,
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
import {
|
||||
checkFilesExist,
|
||||
createNxWorkspace,
|
||||
readFile,
|
||||
readJson
|
||||
} from '../utils';
|
||||
import { checkFilesExist, createNxWorkspace, readJson } from '../utils';
|
||||
|
||||
/**
|
||||
* Too slow to run on CI :(
|
||||
|
||||
@ -2,7 +2,6 @@ import {
|
||||
checkFilesExist,
|
||||
cleanup,
|
||||
copyMissingPackages,
|
||||
readFile,
|
||||
runCLI,
|
||||
runNgNew,
|
||||
updateFile,
|
||||
|
||||
@ -3,23 +3,18 @@ import {
|
||||
branchAndMerge,
|
||||
chain,
|
||||
externalSchematic,
|
||||
filter,
|
||||
MergeStrategy,
|
||||
mergeWith,
|
||||
move,
|
||||
noop,
|
||||
Rule,
|
||||
template,
|
||||
Tree,
|
||||
url,
|
||||
SchematicContext
|
||||
url
|
||||
} from '@angular-devkit/schematics';
|
||||
import { Schema } from './schema';
|
||||
import { strings } from '@angular-devkit/core';
|
||||
import {
|
||||
addImportToModule,
|
||||
insert,
|
||||
getAngularCliConfig,
|
||||
addImportToTestBed,
|
||||
updateJson
|
||||
} from '../../utils/ast-utils';
|
||||
@ -27,13 +22,9 @@ import { toFileName } from '../../utils/name-utils';
|
||||
import * as ts from 'typescript';
|
||||
import { addBootstrapToModule } from '@schematics/angular/utility/ast-utils';
|
||||
import { insertImport } from '@schematics/angular/utility/route-utils';
|
||||
import {
|
||||
addApp,
|
||||
serializeJson,
|
||||
readCliConfigFile
|
||||
} from '../../utils/fileutils';
|
||||
import { addApp, readCliConfigFile } from '../../utils/fileutils';
|
||||
import { offsetFromRoot } from '../../utils/common';
|
||||
import { FormatFiles, wrapIntoFormat } from '../../utils/tasks';
|
||||
import { wrapIntoFormat } from '../../utils/tasks';
|
||||
|
||||
interface NormalizedSchema extends Schema {
|
||||
fullName: string;
|
||||
@ -239,7 +230,7 @@ ts_web_test(
|
||||
)
|
||||
`;
|
||||
|
||||
const sourceFile = host.create(`${path}/app/BUILD.bazel`, ngModule);
|
||||
host.create(`${path}/app/BUILD.bazel`, ngModule);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
import * as path from 'path';
|
||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||
import { getFileContent } from '@schematics/angular/utility/test';
|
||||
|
||||
import { readJson } from '../../utils/ast-utils';
|
||||
|
||||
|
||||
@ -20,11 +20,9 @@ import {
|
||||
addReexport,
|
||||
addRoute,
|
||||
getAngularCliConfig,
|
||||
updateJson,
|
||||
insert
|
||||
} from '../../utils/ast-utils';
|
||||
import { offsetFromRoot } from '../../utils/common';
|
||||
import { addApp, serializeJson } from '../../utils/fileutils';
|
||||
import {
|
||||
names,
|
||||
toClassName,
|
||||
@ -50,21 +48,6 @@ function normalizeOptions(options: Schema): NormalizedSchema {
|
||||
return { ...options, sourceDir: 'src', name, fullName, fullPath };
|
||||
}
|
||||
|
||||
function addLibToAngularCliJson(options: NormalizedSchema): Rule {
|
||||
return updateJson('.angular-cli.json', angularCliJson => {
|
||||
const tags = options.tags ? options.tags.split(',').map(s => s.trim()) : [];
|
||||
angularCliJson.apps = addApp(angularCliJson.apps, {
|
||||
name: options.fullName,
|
||||
root: options.fullPath,
|
||||
test: `${offsetFromRoot(options.fullPath)}test.js`,
|
||||
appRoot: '',
|
||||
tags
|
||||
});
|
||||
|
||||
return angularCliJson;
|
||||
});
|
||||
}
|
||||
|
||||
function addLazyLoadedRouterConfiguration(modulePath: string): Rule {
|
||||
return (host: Tree) => {
|
||||
const moduleSource = host.read(modulePath)!.toString('utf-8');
|
||||
|
||||
@ -18,11 +18,6 @@ import {
|
||||
|
||||
import { Schema } from './schema';
|
||||
|
||||
interface NormalizedSchema extends Schema {
|
||||
fullName: string;
|
||||
fullPath: string;
|
||||
}
|
||||
|
||||
class FormatFiles implements TaskConfigurationGenerator<any> {
|
||||
toConfiguration(): TaskConfiguration<any> {
|
||||
return {
|
||||
|
||||
@ -9,8 +9,7 @@ import { Tree, Rule } from '@angular-devkit/schematics';
|
||||
import {
|
||||
findNodes,
|
||||
getDecoratorMetadata,
|
||||
getSourceNodes,
|
||||
insertAfterLastOccurrence
|
||||
getSourceNodes
|
||||
} from '@schematics/angular/utility/ast-utils';
|
||||
import {
|
||||
Change,
|
||||
@ -196,7 +195,6 @@ ${offset(opts.body, 1, false)}
|
||||
${opts.methodHeader} {}
|
||||
`;
|
||||
|
||||
const pos = clazz.members.length > 0 ? clazz.members.end : clazz.end - 1;
|
||||
return [new InsertChange(modulePath, clazz.end - 1, offset(body, 1, true))];
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import * as fs from 'fs';
|
||||
import * as yargsParser from 'yargs-parser';
|
||||
|
||||
import { readJsonFile } from './fileutils';
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
import { Tree, Rule } from '@angular-devkit/schematics';
|
||||
import { readdirSync, readFileSync } from 'fs';
|
||||
import { Options } from 'prettier';
|
||||
import * as cosmiconfig from 'cosmiconfig';
|
||||
|
||||
import { angularJsVersion } from '../lib-versions';
|
||||
import { Schema } from '../collection/app/schema';
|
||||
|
||||
export function offsetFromRoot(fullPathToSourceDir: string): string {
|
||||
const parts = fullPathToSourceDir.split('/');
|
||||
let offset = '';
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import * as fs from 'fs';
|
||||
import { Tree } from '@angular-devkit/schematics';
|
||||
import * as path from 'path';
|
||||
|
||||
export function updateJsonFile(path: string, callback: (a: any) => any) {
|
||||
|
||||
@ -3,23 +3,12 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { dirSync } from 'tmp';
|
||||
import { lt } from 'semver';
|
||||
import {
|
||||
readFileSync,
|
||||
createReadStream,
|
||||
createWriteStream,
|
||||
writeFileSync
|
||||
} from 'fs';
|
||||
import { writeFileSync } from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as yargsParser from 'yargs-parser';
|
||||
|
||||
import { readJsonFile } from '../src/utils/fileutils';
|
||||
|
||||
interface CommandOptions {
|
||||
directory?: string;
|
||||
yarn: boolean;
|
||||
help: boolean;
|
||||
}
|
||||
|
||||
const parsedArgs = yargsParser(process.argv, {
|
||||
string: ['directory'],
|
||||
boolean: ['yarn', 'help']
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { updateJsonFile } from '../src/utils/fileutils';
|
||||
import {
|
||||
devKitCoreVersion,
|
||||
devKitSchematicsVersion,
|
||||
schematicsAngularVersion
|
||||
} from '../src/lib-versions';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { writeFileSync, readFileSync, readdirSync, unlinkSync } from 'fs';
|
||||
import { writeFileSync, unlinkSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { updateJsonFile } from '../src/utils/fileutils';
|
||||
|
||||
@ -3,27 +3,19 @@ import {
|
||||
branchAndMerge,
|
||||
chain,
|
||||
externalSchematic,
|
||||
filter,
|
||||
MergeStrategy,
|
||||
mergeWith,
|
||||
move,
|
||||
noop,
|
||||
Rule,
|
||||
template,
|
||||
Tree,
|
||||
url,
|
||||
SchematicContext
|
||||
url
|
||||
} from '@angular-devkit/schematics';
|
||||
import { Schema } from './schema';
|
||||
import { strings } from '@angular-devkit/core';
|
||||
import * as ts from 'typescript';
|
||||
import { addBootstrapToModule } from '@schematics/angular/utility/ast-utils';
|
||||
import { insertImport } from '@schematics/angular/utility/route-utils';
|
||||
import {
|
||||
addApp,
|
||||
serializeJson,
|
||||
readCliConfigFile
|
||||
} from '../../utils/fileutils';
|
||||
import { addApp, readCliConfigFile } from '../../utils/fileutils';
|
||||
import {
|
||||
addImportToModule,
|
||||
addImportToTestBed,
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
import * as path from 'path';
|
||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||
import { createEmptyWorkspace } from '../../utils/testing-utils';
|
||||
import { getFileContent } from '@schematics/angular/utility/test';
|
||||
import { readJson } from '../../utils/ast-utils';
|
||||
|
||||
describe('application', () => {
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
} from '@angular-devkit/schematics';
|
||||
import { Schema } from './schema';
|
||||
import * as path from 'path';
|
||||
import { addApp, serializeJson } from '../../utils/fileutils';
|
||||
import { addApp } from '../../utils/fileutils';
|
||||
import { insertImport } from '@schematics/angular/utility/route-utils';
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
|
||||
@ -32,7 +32,6 @@ import {
|
||||
routerStoreVersion,
|
||||
ngrxStoreFreezeVersion
|
||||
} from '../../lib-versions';
|
||||
import { serializeJson } from '../../utils/fileutils';
|
||||
import { wrapIntoFormat } from '../../utils/tasks';
|
||||
|
||||
function addImportsToModule(name: string, options: Schema): Rule {
|
||||
|
||||
@ -12,21 +12,14 @@ import {
|
||||
url
|
||||
} from '@angular-devkit/schematics';
|
||||
|
||||
import {
|
||||
names,
|
||||
toClassName,
|
||||
toFileName,
|
||||
toPropertyName
|
||||
} from '../../utils/name-utils';
|
||||
import { names, toClassName, toFileName } from '../../utils/name-utils';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
addDeclarationToModule,
|
||||
addEntryComponents,
|
||||
addImportToModule,
|
||||
addMethod,
|
||||
addParameterToConstructor,
|
||||
addProviderToModule,
|
||||
getBootstrapComponent,
|
||||
insert,
|
||||
readBootstrapInfo,
|
||||
@ -34,7 +27,6 @@ import {
|
||||
} from '../../utils/ast-utils';
|
||||
import { insertImport } from '@schematics/angular/utility/route-utils';
|
||||
import { Schema } from './schema';
|
||||
import { angularJsVersion } from '../../lib-versions';
|
||||
import { addUpgradeToPackageJson } from '../../utils/common';
|
||||
import { wrapIntoFormat } from '../../utils/tasks';
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ import {
|
||||
schematicsVersion
|
||||
} from '../../lib-versions';
|
||||
import * as fs from 'fs';
|
||||
import { copyFile, serializeJson, updateJsonFile } from '../../utils/fileutils';
|
||||
import { updateJsonFile } from '../../utils/fileutils';
|
||||
import {
|
||||
resolveUserExistingPrettierConfig,
|
||||
DEFAULT_NRWL_PRETTIER_CONFIG
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
import * as path from 'path';
|
||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||
import { getFileContent } from '@schematics/angular/utility/test';
|
||||
|
||||
describe('workspace', () => {
|
||||
const schematicRunner = new SchematicTestRunner(
|
||||
@ -17,22 +16,14 @@ describe('workspace', () => {
|
||||
|
||||
it('should error if no package.json is present', () => {
|
||||
expect(() => {
|
||||
const tree = schematicRunner.runSchematic(
|
||||
'workspace',
|
||||
{ name: 'myApp' },
|
||||
appTree
|
||||
);
|
||||
schematicRunner.runSchematic('workspace', { name: 'myApp' }, appTree);
|
||||
}).toThrow('Cannot find package.json');
|
||||
});
|
||||
|
||||
it('should error if no protractor.conf.js is present', () => {
|
||||
expect(() => {
|
||||
appTree.create('/package.json', JSON.stringify({}));
|
||||
const tree = schematicRunner.runSchematic(
|
||||
'workspace',
|
||||
{ name: 'myApp' },
|
||||
appTree
|
||||
);
|
||||
schematicRunner.runSchematic('workspace', { name: 'myApp' }, appTree);
|
||||
}).toThrow('Cannot find protractor.conf.js');
|
||||
});
|
||||
|
||||
@ -40,11 +31,7 @@ describe('workspace', () => {
|
||||
expect(() => {
|
||||
appTree.create('/package.json', JSON.stringify({}));
|
||||
appTree.create('/protractor.conf.js', '');
|
||||
const tree = schematicRunner.runSchematic(
|
||||
'workspace',
|
||||
{ name: 'myApp' },
|
||||
appTree
|
||||
);
|
||||
schematicRunner.runSchematic('workspace', { name: 'myApp' }, appTree);
|
||||
}).toThrow('Cannot find .angular-cli.json');
|
||||
});
|
||||
|
||||
@ -58,11 +45,7 @@ describe('workspace', () => {
|
||||
apps: [{}, {}]
|
||||
})
|
||||
);
|
||||
const tree = schematicRunner.runSchematic(
|
||||
'workspace',
|
||||
{ name: 'myApp' },
|
||||
appTree
|
||||
);
|
||||
schematicRunner.runSchematic('workspace', { name: 'myApp' }, appTree);
|
||||
}).toThrow('Can only convert projects with one app');
|
||||
});
|
||||
});
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
dependencies,
|
||||
Dependency
|
||||
} from '@nrwl/schematics/src/command-line/affected-apps';
|
||||
import { readFileSync, statSync } from 'fs';
|
||||
import { statSync } from 'fs';
|
||||
import * as appRoot from 'app-root-path';
|
||||
import { readJsonFile } from '../utils/fileutils';
|
||||
|
||||
|
||||
@ -9,8 +9,7 @@ import { Tree, Rule } from '@angular-devkit/schematics';
|
||||
import {
|
||||
findNodes,
|
||||
getDecoratorMetadata,
|
||||
getSourceNodes,
|
||||
insertAfterLastOccurrence
|
||||
getSourceNodes
|
||||
} from '@schematics/angular/utility/ast-utils';
|
||||
import {
|
||||
Change,
|
||||
@ -196,7 +195,6 @@ ${offset(opts.body, 1, false)}
|
||||
${opts.methodHeader} {}
|
||||
`;
|
||||
|
||||
const pos = clazz.members.length > 0 ? clazz.members.end : clazz.end - 1;
|
||||
return [new InsertChange(modulePath, clazz.end - 1, offset(body, 1, true))];
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import * as fs from 'fs';
|
||||
import * as yargsParser from 'yargs-parser';
|
||||
|
||||
import { readJsonFile } from './fileutils';
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
import { Tree, Rule } from '@angular-devkit/schematics';
|
||||
import { readdirSync, readFileSync } from 'fs';
|
||||
import { Rule } from '@angular-devkit/schematics';
|
||||
import { Options } from 'prettier';
|
||||
import * as cosmiconfig from 'cosmiconfig';
|
||||
|
||||
import { angularJsVersion } from '../lib-versions';
|
||||
import { serializeJson } from './fileutils';
|
||||
import { Schema } from '../collection/app/schema';
|
||||
import { updateJson } from './ast-utils';
|
||||
|
||||
export function addUpgradeToPackageJson(): Rule {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import * as fs from 'fs';
|
||||
import { Tree } from '@angular-devkit/schematics';
|
||||
import * as path from 'path';
|
||||
|
||||
export function readJsonFile(path: string) {
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
"typeRoots": ["node_modules/@types"],
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"noUnusedLocals": true,
|
||||
"skipLibCheck": true,
|
||||
"lib": ["es2017"],
|
||||
"declaration": true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user