Skip to content

Commit

Permalink
refactor: additional lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin committed May 30, 2018
1 parent 796a51e commit 77f2dfd
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"test:messages": "node scripts/test-commit-messages.js",
"test:packages": "node scripts/run-packages-spec.js",
"eslint": "eslint .",
"tslint": "tslint \"**/*.ts\" -c tslint.json -e \"**/config/schema.d.ts\" -e \"**/tests/**\" -e \"node_modules/**\" -e \"tmp/**\" -e \"dist/**\"",
"tslint": "tslint \"**/*.ts\" -c tslint.json -e \"**/config/schema.d.ts\" -e \"**/tests/**\" -e \"node_modules/**\" -e \"tmp/**\" -e \"dist/**\" -e \"tools/**\"",
"lint": "npm-run-all -c eslint tslint",
"tool": "node scripts/run-tool.js"
},
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/add.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { tags, terminal } from '@angular-devkit/core';
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
import { CommandScope, Option } from '../models/command';
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/build.ts
Expand Up @@ -18,6 +18,7 @@ export default class BuildCommand extends ArchitectCommand {
// Check Angular and TypeScript versions.
Version.assertCompatibleAngularVersion(this.project.root);
Version.assertTypescriptVersion(this.project.root);

return super.validate(options);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/@angular/cli/commands/config.ts
Expand Up @@ -105,6 +105,7 @@ function setValueFromPath<T extends JsonArray | JsonObject>(
value[current] = {};
}
}

return value[current];
} else if (typeof current == 'number' && Array.isArray(value)) {
if (index === fragments.length - 1) {
Expand All @@ -116,6 +117,7 @@ function setValueFromPath<T extends JsonArray | JsonObject>(
value[current] = {};
}
}

return value[current];
} else {
return undefined;
Expand Down Expand Up @@ -211,7 +213,12 @@ export default class ConfigCommand extends Command {
}

private get(config: experimental.workspace.WorkspaceSchema, options: ConfigOptions) {
const value = options.jsonPath ? getValueFromPath(config as any, options.jsonPath) : config;
let value;
if (options.jsonPath) {
value = getValueFromPath(config as {} as JsonObject, options.jsonPath);
} else {
value = config;
}

if (value === undefined) {
this.logger.error('Value cannot be found.');
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/doc.ts
Expand Up @@ -24,6 +24,7 @@ export default class DocCommand extends Command {
public validate(options: Options) {
if (!options.keyword) {
this.logger.error(`keyword argument is required.`);

return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/commands/easter-egg.ts
Expand Up @@ -12,7 +12,7 @@ export default class AwesomeCommand extends Command {
readonly arguments: string[] = [];
readonly options: Option[] = [];

run(_options: any) {
run() {
const phrase = pickOne([
`You're on it, there's nothing for me to do!`,
`Let's take a look... nope, it's all good!`,
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/generate.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { tags, terminal } from '@angular-devkit/core';
import { CommandScope, Option } from '../models/command';
import { SchematicCommand } from '../models/schematic-command';
Expand Down
2 changes: 2 additions & 0 deletions packages/@angular/cli/commands/help.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { terminal } from '@angular-devkit/core';
import { Command, Option } from '../models/command';

Expand All @@ -13,6 +14,7 @@ export default class HelpCommand extends Command {
.map(key => {
const Cmd = options.commandMap[key];
const command: Command = new Cmd(null, null);

return command;
})
.filter(cmd => !cmd.hidden && !cmd.unknown)
Expand Down
2 changes: 2 additions & 0 deletions packages/@angular/cli/commands/new.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { CommandScope, Option } from '../models/command';
import { SchematicCommand } from '../models/schematic-command';
import { getDefaultSchematicCollection } from '../utilities/config';
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class NewCommand extends SchematicCommand {
const opts = Object.assign({}, options);
delete opts.verbose;
delete opts.collection;

return opts;
}
}
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/serve.ts
Expand Up @@ -18,6 +18,7 @@ export default class ServeCommand extends ArchitectCommand {
// Check Angular and TypeScript versions.
Version.assertCompatibleAngularVersion(this.project.root);
Version.assertTypescriptVersion(this.project.root);

return true;
}

Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/update.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { normalize } from '@angular-devkit/core';
import { CommandScope, Option } from '../models/command';
import { CoreSchematicOptions, SchematicCommand } from '../models/schematic-command';
Expand Down
8 changes: 6 additions & 2 deletions packages/@angular/cli/commands/version.ts
Expand Up @@ -13,11 +13,11 @@ export default class VersionCommand extends Command {
public readonly arguments: string[] = [];
public readonly options: Option[] = [];

public run(_options: any) {
public run() {
let angularCoreVersion = '';
const angularSameAsCore: string[] = [];
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
let projPkg: any;
let projPkg;
try {
projPkg = require(path.resolve(this.project.root, 'package.json'));
} catch (exception) {
Expand Down Expand Up @@ -66,6 +66,7 @@ export default class VersionCommand extends Command {
}

acc[name] = this.getVersion(name, packageRoot, maybeNodeModules);

return acc;
}, {} as { [module: string]: string });

Expand Down Expand Up @@ -124,6 +125,7 @@ export default class VersionCommand extends Command {
} else {
acc[acc.length - 1] = line;
}
return acc;
}, []).join('\n... ')}
Expand All @@ -144,6 +146,7 @@ export default class VersionCommand extends Command {
try {
if (projectNodeModules) {
const modulePkg = require(path.resolve(projectNodeModules, moduleName, 'package.json'));

return modulePkg.version;
}
} catch (_) {
Expand All @@ -152,6 +155,7 @@ export default class VersionCommand extends Command {
try {
if (cliNodeModules) {
const modulePkg = require(path.resolve(cliNodeModules, moduleName, 'package.json'));

return modulePkg.version + ' (cli-only)';
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/custom-typings.d.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
declare module 'yargs-parser' {
const parseOptions: any;
const yargsParser: <T = any>(args: string | string[], options?: parseOptions) => T;
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/lib/cli/index.ts
Expand Up @@ -39,7 +39,7 @@ function loadCommands() {
};
}

export default async function(options: any) {
export default async function(options: { testing?: boolean, cliArgs: string[] }) {
const commands = loadCommands();

const logger = new logging.IndentLogger('cling');
Expand Down Expand Up @@ -83,6 +83,7 @@ export default async function(options: any) {
}

loggingSubscription.unsubscribe();

return 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@angular/cli/lib/init.ts
Expand Up @@ -41,9 +41,9 @@ function _fromPackageJson(cwd?: string) {

// Check if we need to profile this CLI run.
if (process.env['NG_CLI_PROFILING']) {
const profiler = require('v8-profiler');
const profiler = require('v8-profiler'); // tslint:disable-line:no-implicit-dependencies
profiler.startProfiling();
function exitHandler(options: any, _err: Error) {
function exitHandler(options: { cleanup: boolean, exit: boolean }, _err: Error) {
if (options.cleanup) {
const cpuProfile = profiler.stopProfiling();
fs.writeFileSync(path.resolve(process.cwd(), process.env.NG_CLI_PROFILING) + '.cpuprofile',
Expand Down
7 changes: 6 additions & 1 deletion packages/@angular/cli/models/architect-command.ts
@@ -1,5 +1,8 @@
// tslint:disable:no-any
import {
Architect, BuildEvent, BuilderDescription,
Architect,
BuildEvent,
BuilderDescription,
TargetSpecifier,
} from '@angular-devkit/architect';
import { JsonObject, experimental, schema, strings } from '@angular-devkit/core';
Expand Down Expand Up @@ -84,6 +87,7 @@ export abstract class ArchitectCommand extends Command<ArchitectCommandOptions>
+ `'${this.target}' would be run on the following projects: ${projectNames.join()}`);
}
}

return true;
}

Expand Down Expand Up @@ -187,6 +191,7 @@ export abstract class ArchitectCommand extends Command<ArchitectCommandOptions>

if (newErrors.length > 0) {
this.logger.error(new schema.SchemaValidationException(newErrors).message);

return 1;
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/@angular/cli/models/command-runner.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { logging, tags } from '@angular-devkit/core';
import { camelize } from '@angular-devkit/core/src/utils/strings';
import {
Expand Down Expand Up @@ -85,6 +86,7 @@ export async function runCommand(commandMap: CommandMap,
if (!(b in commandsDistance)) {
commandsDistance[b] = levenshtein(b, commandName);
}

return commandsDistance[a] - commandsDistance[b];
});

Expand Down Expand Up @@ -176,6 +178,7 @@ export function parseOptions<T = any>(
.reduce((aliases: any, opt: Option) => {
aliases[opt.name] = opt.aliases
.filter(a => a.length === 1);

return aliases;
}, {});

Expand All @@ -187,6 +190,7 @@ export function parseOptions<T = any>(
.filter(o => o.default !== undefined || booleans.indexOf(o.name) !== -1)
.reduce((defaults: any, opt: Option) => {
defaults[opt.name] = opt.default;

return defaults;
}, {});

Expand Down Expand Up @@ -277,6 +281,7 @@ function findCommand(map: CommandMap, name: string): CommandConstructor | null {
if (!Cmd) {
return null;
}

return Cmd;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@angular/cli/models/command.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { logging, terminal } from '@angular-devkit/core';

export interface CommandConstructor {
Expand Down Expand Up @@ -30,6 +31,7 @@ export abstract class Command<T = any> {

async initializeRaw(args: string[]): Promise<any> {
this._rawArgs = args;

return args;
}
async initialize(_options: any): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/error.ts
Expand Up @@ -5,7 +5,7 @@ export class NgToolkitError extends Error {
if (message) {
this.message = message;
} else {
this.message = (<any> this.constructor).name;
this.message = this.constructor.name;
}
}
}
5 changes: 5 additions & 0 deletions packages/@angular/cli/models/schematic-command.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { JsonObject, experimental } from '@angular-devkit/core';
import { normalize, strings, tags, terminal, virtualFs } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
Expand Down Expand Up @@ -70,12 +71,14 @@ export abstract class SchematicCommand extends Command {
if (workingDir === '') {
return {};
}

return this.options
.filter(o => o.format === 'path')
.map(o => o.name)
.filter(name => options[name] === undefined)
.reduce((acc: any, curr) => {
acc[curr] = workingDir;

return acc;
}, {});
}
Expand Down Expand Up @@ -120,6 +123,7 @@ export abstract class SchematicCommand extends Command {
return this._workspace.getProjectByPath(normalize(process.cwd()))
|| this._workspace.getDefaultProjectName();
}

return undefined;
});

Expand Down Expand Up @@ -214,6 +218,7 @@ export abstract class SchematicCommand extends Command {
if (this._originalOptions.find(option => option.name == 'debug')) {
delete opts.debug;
}

return opts;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/@angular/cli/utilities/config.ts
Expand Up @@ -60,6 +60,7 @@ export function getWorkspace(

if (!configPath) {
cachedWorkspaces.set(level, null);

return null;
}

Expand All @@ -72,6 +73,7 @@ export function getWorkspace(

workspace.loadWorkspaceFromHost(file).subscribe();
cachedWorkspaces.set(level, workspace);

return workspace;
}

Expand Down Expand Up @@ -109,6 +111,7 @@ export function getWorkspaceRaw(
if (ast.kind != 'object') {
throw new Error('Invalid JSON');
}

return [ast as JsonAstObject, configPath];
}

Expand Down Expand Up @@ -164,6 +167,7 @@ export function getPackageManager(): string {
return legacyPackageManager;
}
}

return 'npm';
}

Expand Down Expand Up @@ -211,6 +215,7 @@ export function migrateLegacyGlobalConfig(): boolean {
if (Object.getOwnPropertyNames(cli).length > 0) {
const globalPath = path.join(homeDir, globalFileName);
writeFileSync(globalPath, JSON.stringify({ version: 1, cli }, null, 2));

return true;
}
}
Expand Down Expand Up @@ -238,6 +243,7 @@ function getLegacyPackageManager(): string | null {
}
}
}

return null;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@angular/cli/utilities/project.ts
@@ -1,3 +1,4 @@
// tslint:disable:no-any
import { normalize } from '@angular-devkit/core';
import * as fs from 'fs';
import * as os from 'os';
Expand Down Expand Up @@ -44,6 +45,7 @@ export function getProjectDetails(): ProjectDetails | null {
return null;
}
}

return {
root: possibleDir,
configFile: configFileName,
Expand All @@ -60,5 +62,6 @@ function containsCliDep(obj: any): boolean {
return true;
}
}

return false;
}
2 changes: 1 addition & 1 deletion packages/@angular/cli/utilities/schematics.ts
Expand Up @@ -4,7 +4,7 @@
*
* require('@schematics/angular')
*/

// tslint:disable:no-any
import { schema } from '@angular-devkit/core';
import {
Collection,
Expand Down

0 comments on commit 77f2dfd

Please sign in to comment.