Skip to content

Commit

Permalink
refactor: add rule for no unused locals and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Mar 27, 2018
1 parent 113b51b commit edac12c
Show file tree
Hide file tree
Showing 29 changed files with 23 additions and 139 deletions.
9 changes: 1 addition & 8 deletions e2e/schematics/application.test.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
9 changes: 1 addition & 8 deletions e2e/schematics/bazel-application.test.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
1 change: 0 additions & 1 deletion e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
newApp,
newLib,
newProject,
readFile,
runCLI,
runCommand,
updateFile,
Expand Down
7 changes: 1 addition & 6 deletions e2e/schematics/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
checkFilesExist,
createNxWorkspace,
readFile,
readJson
} from '../utils';
import { checkFilesExist, createNxWorkspace, readJson } from '../utils';

/**
* Too slow to run on CI :(
Expand Down
1 change: 0 additions & 1 deletion e2e/schematics/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
checkFilesExist,
cleanup,
copyMissingPackages,
readFile,
runCLI,
runNgNew,
updateFile,
Expand Down
17 changes: 4 additions & 13 deletions packages/bazel/src/collection/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@ 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';
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;
Expand Down Expand Up @@ -239,7 +230,7 @@ ts_web_test(
)
`;

const sourceFile = host.create(`${path}/app/BUILD.bazel`, ngModule);
host.create(`${path}/app/BUILD.bazel`, ngModule);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
17 changes: 0 additions & 17 deletions packages/bazel/src/collection/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand Down
5 changes: 0 additions & 5 deletions packages/bazel/src/collection/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions packages/bazel/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))];
}

Expand Down
1 change: 0 additions & 1 deletion packages/bazel/src/utils/cli-config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as fs from 'fs';
import * as yargsParser from 'yargs-parser';

import { readJsonFile } from './fileutils';
Expand Down
5 changes: 0 additions & 5 deletions packages/bazel/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -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 = '';
Expand Down
1 change: 0 additions & 1 deletion packages/bazel/src/utils/fileutils.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
13 changes: 1 addition & 12 deletions packages/schematics/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { updateJsonFile } from '../src/utils/fileutils';
import {
devKitCoreVersion,
devKitSchematicsVersion,
schematicsAngularVersion
} from '../src/lib-versions';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
12 changes: 2 additions & 10 deletions packages/schematics/src/collection/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/collection/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion packages/schematics/src/collection/ngrx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 1 addition & 9 deletions packages/schematics/src/collection/upgrade-module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,21 @@ 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,
removeFromNgModule
} 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';

Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/collection/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 4 additions & 21 deletions packages/schematics/src/collection/workspace/workspace.spec.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -17,34 +16,22 @@ 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');
});

it('should error if no .angular-cli.json is present', () => {
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');
});

Expand All @@ -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');
});
});
2 changes: 1 addition & 1 deletion packages/schematics/src/command-line/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading

0 comments on commit edac12c

Please sign in to comment.