Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update eslint, config, and plugins (#737)
Including automatic and manual lint fixes

* test/helpers: assertStubbedCalls and stub
  • Loading branch information
evocateur committed Apr 6, 2017
1 parent c9ed57a commit c2fbcb2
Show file tree
Hide file tree
Showing 36 changed files with 316 additions and 342 deletions.
10 changes: 1 addition & 9 deletions .eslintrc
@@ -1,11 +1,3 @@
{
"extends": "babel",
"rules": {
"space-infix-ops": 2,
"no-confusing-arrow": 0,
"max-len": 0
},
"env": {
"node": true
}
"extends": "babel"
}
3 changes: 3 additions & 0 deletions bin/lerna.js
@@ -1,6 +1,9 @@
#!/usr/bin/env node
"use strict";

/* eslint-disable max-len */
// too many long lines in this file to bother

const lerna = require("../lib/index");
const logger = require("../lib/logger");
const chalk = require("chalk");
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -64,15 +64,15 @@
},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-eslint": "^6.0.2",
"babel-eslint": "^7.2.1",
"babel-jest": "^19.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.0",
"eslint": "^2.3.0",
"eslint-config-babel": "^1.0.1",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-flow-vars": "^0.5.0",
"eslint": "^3.19.0",
"eslint-config-babel": "^6.0.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.30.4",
"jest": "^19.0.2",
"normalize-newline": "^3.0.0",
"normalize-path": "^2.1.1"
Expand Down
2 changes: 1 addition & 1 deletion src/ChildProcessUtilities.js
@@ -1,6 +1,6 @@
import child from "child_process";
import spawn from "cross-spawn";
import {EventEmitter} from "events";
import { EventEmitter } from "events";

// Keep track of how many live children we have.
let children = 0;
Expand Down
9 changes: 6 additions & 3 deletions src/Command.js
Expand Up @@ -67,7 +67,7 @@ export default class Command {
getOptions(...objects) {

// Command config object is either "commands" or "command".
const {commands, command} = this.repository.lernaJson;
const { commands, command } = this.repository.lernaJson;

// Items lower down override items higher up.
return Object.assign(
Expand Down Expand Up @@ -147,6 +147,8 @@ export default class Command {
return;
}

/* eslint-disable max-len */
// TODO: remove these warnings eventually
if (FileSystemUtilities.existsSync(this.repository.versionLocation)) {
this.logger.warn("You have a `VERSION` file in your repository, this is leftover from a previous version. Please run `lerna init` to update.");
this._complete(null, 1);
Expand All @@ -170,10 +172,11 @@ export default class Command {
this._complete(null, 1);
return;
}
/* eslint-enable max-len */
}

runPreparations() {
const {scope, ignore, registry} = this.getOptions();
const { scope, ignore, registry } = this.getOptions();

if (scope) {
this.logger.info(`Scoping to packages that match '${scope}'`);
Expand All @@ -188,7 +191,7 @@ export default class Command {
this.repository.buildPackageGraph();
this.packages = this.repository.packages;
this.packageGraph = this.repository.packageGraph;
this.filteredPackages = PackageUtilities.filterPackages(this.packages, {scope, ignore});
this.filteredPackages = PackageUtilities.filterPackages(this.packages, { scope, ignore });
if (this.getOptions().includeFilteredDependencies) {
this.filteredPackages = PackageUtilities.addDependencies(this.filteredPackages, this.packageGraph);
}
Expand Down
8 changes: 6 additions & 2 deletions src/ConventionalCommitUtilities.js
Expand Up @@ -11,6 +11,9 @@ const CHANGELOG_HEADER = dedent(`# Change Log
All notable changes to this project will be documented in this file.
See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.`);

const RECOMMEND_CLI = require.resolve("conventional-recommended-bump/cli.js");
const CHANGELOG_CLI = require.resolve("conventional-changelog-cli/cli.js");

export default class ConventionalCommitUtilities {
@logger.logifySync()
static recommendVersion(pkg, opts) {
Expand All @@ -19,7 +22,7 @@ export default class ConventionalCommitUtilities {
const pkgLocation = pkg.location;

const recommendedBump = ChildProcessUtilities.execSync(
`${require.resolve("conventional-recommended-bump/cli.js")} -l ${name} --commit-path=${pkgLocation} -p angular`,
`${RECOMMEND_CLI} -l ${name} --commit-path=${pkgLocation} -p angular`,
opts
);

Expand All @@ -30,6 +33,7 @@ export default class ConventionalCommitUtilities {
static updateChangelog(pkg, opts) {
const name = pkg.name;
const pkgLocation = pkg.location;
const pkgJsonLocation = path.join(pkgLocation, "package.json");
const changelogLocation = ConventionalCommitUtilities.changelogLocation(pkg);

let changelogContents = "";
Expand All @@ -40,7 +44,7 @@ export default class ConventionalCommitUtilities {
// run conventional-changelog-cli to generate the markdown
// for the upcoming release.
const newEntry = ChildProcessUtilities.execSync(
`${require.resolve("conventional-changelog-cli/cli.js")} -l ${name} --commit-path=${pkgLocation} --pkg=${path.join(pkgLocation, "package.json")} -p angular`,
`${CHANGELOG_CLI} -l ${name} --commit-path=${pkgLocation} --pkg=${pkgJsonLocation} -p angular`,
opts
);

Expand Down
4 changes: 2 additions & 2 deletions src/FileSystemUtilities.js
Expand Up @@ -140,12 +140,12 @@ function resolveSymbolicLink(filePath) {
}

function resolvePosixSymlink(filePath) {
const {isSymlink} = resolveSymbolicLink(filePath);
const { isSymlink } = resolveSymbolicLink(filePath);
return isSymlink;
}

function resolveWindowsSymlink(filePath) {
const {isSymlink, lstat} = resolveSymbolicLink(filePath);
const { isSymlink, lstat } = resolveSymbolicLink(filePath);

if (lstat.isFile() && !isSymlink) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/GitUtilities.js
Expand Up @@ -83,7 +83,7 @@ export default class GitUtilities {

@logger.logifySync()
static diffSinceIn(since, location, opts) {
return ChildProcessUtilities.execSync("git diff --name-only " + since + " -- " + escapeArgs(location), opts);
return ChildProcessUtilities.execSync(`git diff --name-only ${since} -- ${escapeArgs(location)}`, opts);
}

@logger.logifySync()
Expand Down
5 changes: 4 additions & 1 deletion src/NpmUtilities.js
Expand Up @@ -87,7 +87,10 @@ export default class NpmUtilities {

@logger.logifyAsync()
static runScriptInDir(script, args, directory, callback) {
ChildProcessUtilities.exec(`npm run ${script} ${escapeArgs(args)}`, { cwd: directory, env: process.env }, callback);
ChildProcessUtilities.exec(`npm run ${script} ${escapeArgs(args)}`, {
cwd: directory,
env: process.env,
}, callback);
}

@logger.logifyAsync()
Expand Down
6 changes: 3 additions & 3 deletions src/PackageUtilities.js
Expand Up @@ -170,9 +170,9 @@ export default class PackageUtilities {
);
}

batch.push(packages.reduce((a, b) => (
(refCounts[a.name] || 0) > (refCounts[b.name] || 0) ? a : b
)));
batch.push(packages.reduce((a, b) => {
return (refCounts[a.name] || 0) > (refCounts[b.name] || 0) ? a : b;
}));
}

batches.push(batch);
Expand Down
4 changes: 2 additions & 2 deletions src/PromptUtilities.js
Expand Up @@ -14,7 +14,7 @@ export default class PromptUtilities {
}]).then((answers) => callback(answers.confirm));
}

static select(message, {choices, filter, validate} = {}, callback) {
static select(message, { choices, filter, validate } = {}, callback) {
inquirer.prompt([{
type: "list",
name: "prompt",
Expand All @@ -26,7 +26,7 @@ export default class PromptUtilities {
}]).then((answers) => callback(answers.prompt));
}

static input(message, {filter, validate} = {}, callback) {
static input(message, { filter, validate } = {}, callback) {
inquirer.prompt([{
type: "input",
name: "input",
Expand Down
16 changes: 12 additions & 4 deletions src/UpdatedPackagesCollector.js
Expand Up @@ -53,7 +53,10 @@ export default class UpdatedPackagesCollector {

commits = this.getAssociatedCommits(currentSHA);
} else if (hasTags) {
commits = GitUtilities.describeTag(GitUtilities.getLastTaggedCommitInBranch(this.execOpts), this.execOpts);
commits = GitUtilities.describeTag(
GitUtilities.getLastTaggedCommitInBranch(this.execOpts),
this.execOpts
);
}

const updatedPackages = {};
Expand Down Expand Up @@ -94,7 +97,7 @@ export default class UpdatedPackagesCollector {
return false;
}

let dependencies = this.packageGraph.get(packageName).dependencies;
const dependencies = this.packageGraph.get(packageName).dependencies;

if (dependencies.indexOf(dependency) > -1) {
this.cache[packageName][dependency] = "dependent";
Expand Down Expand Up @@ -132,7 +135,11 @@ export default class UpdatedPackagesCollector {

collectUpdates() {
return this.packages.filter((pkg) => {
return this.updatedPackages[pkg.name] || (this.flags[SECRET_FLAG] ? false : this.dependents[pkg.name]) || this.flags.canary;
return (
this.updatedPackages[pkg.name] ||
(this.flags[SECRET_FLAG] ? false : this.dependents[pkg.name]) ||
this.flags.canary
);
}).map((pkg) => {
return new Update(pkg);
});
Expand All @@ -159,7 +166,7 @@ export default class UpdatedPackagesCollector {
if (this.flags.ignore) {
changedFiles = changedFiles.filter((file) => {
return !find(this.flags.ignore, (pattern) => {
return minimatch(file, pattern, {matchBase: true});
return minimatch(file, pattern, { matchBase: true });
});
});
}
Expand All @@ -168,4 +175,5 @@ export default class UpdatedPackagesCollector {
}
}

// eslint-disable-next-line max-len
const SECRET_FLAG = new Buffer("ZGFuZ2Vyb3VzbHlPbmx5UHVibGlzaEV4cGxpY2l0VXBkYXRlc1RoaXNJc0FDdXN0b21GbGFnRm9yQmFiZWxBbmRZb3VTaG91bGROb3RCZVVzaW5nSXRKdXN0RGVhbFdpdGhNb3JlUGFja2FnZXNCZWluZ1B1Ymxpc2hlZEl0SXNOb3RBQmlnRGVhbA==", "base64").toString("ascii");
54 changes: 33 additions & 21 deletions src/commands/BootstrapCommand.js
Expand Up @@ -15,7 +15,7 @@ export default class BootstrapCommand extends Command {
};

this.batchedPackages = this.toposort
? PackageUtilities.topologicallyBatchPackages(this.filteredPackages, {logger: this.logger})
? PackageUtilities.topologicallyBatchPackages(this.filteredPackages, { logger: this.logger })
: [ this.filteredPackages ];

callback(null, true);
Expand Down Expand Up @@ -149,7 +149,7 @@ export default class BootstrapCommand extends Command {
* @param {Array.<String>} packages
*/
dependencySatisfiesPackages(dependency, packages) {
const {version} = (this.hoistedPackageJson(dependency) || {});
const { version } = (this.hoistedPackageJson(dependency) || {});
return packages.every((pkg) => {
return semver.satisfies(
version,
Expand Down Expand Up @@ -215,8 +215,8 @@ export default class BootstrapCommand extends Command {
Object.keys(this.repository.package.allDependencies).forEach((name) => {
const version = this.repository.package.allDependencies[name];
depsToInstall[name] = {
versions : {[version]: 0},
dependents : {[version]: []},
versions : { [version]: 0 },
dependents : { [version]: [] },
};
});

Expand All @@ -227,12 +227,15 @@ export default class BootstrapCommand extends Command {
Object.keys(pkg.allDependencies)

// map to package or normalized external dependency
.map((name) => findPackage(name, pkg.allDependencies[name]) || { name, version: pkg.allDependencies[name] })
.map((name) => (
findPackage(name, pkg.allDependencies[name]) ||
{ name, version: pkg.allDependencies[name] }
))

// match external and version mismatched local packages
.filter((dep) => !hasPackage(dep.name, dep.version) || !pkg.hasMatchingDependency(dep, this.logger))

.forEach(({name, version}) => {
.forEach(({ name, version }) => {

// Get the object for this package, auto-vivifying.
const dep = depsToInstall[name] || (depsToInstall[name] = {
Expand All @@ -254,15 +257,15 @@ export default class BootstrapCommand extends Command {

// determine where each dependency will be installed
Object.keys(depsToInstall).forEach((name) => {
const {versions, dependents} = depsToInstall[name];
const { versions, dependents } = depsToInstall[name];

let rootVersion;

if (hoist && PackageUtilities.isHoistedPackage(name, hoist, nohoist)) {

// Get the most common version.
const commonVersion = Object.keys(versions)
.reduce((a, b) => versions[a] > versions[b] ? a : b);
.reduce((a, b) => { return versions[a] > versions[b] ? a : b; });

// Get the version required by the repo root (if any).
// If the root doesn't have a dependency on this package then we'll
Expand Down Expand Up @@ -319,7 +322,7 @@ export default class BootstrapCommand extends Command {
* @param {Function} callback
*/
installExternalDependencies(callback) {
const {leaves, root} = this.getDependenciesToInstall(this.filteredPackages);
const { leaves, root } = this.getDependenciesToInstall(this.filteredPackages);
const actions = [];

// Start root install first, if any, since it's likely to take the longest.
Expand All @@ -328,8 +331,8 @@ export default class BootstrapCommand extends Command {
// If we have anything to install in the root then we'll install
// _everything_ that needs to go there. This is important for
// consistent behavior across npm clients.
const depsToInstallInRoot = root.some(({isSatisfied}) => !isSatisfied)
? root.map(({dependency}) => dependency)
const depsToInstallInRoot = root.some(({ isSatisfied }) => !isSatisfied)
? root.map(({ dependency }) => dependency)
: [];

actions.push((cb) => NpmUtilities.installInDir(
Expand All @@ -341,8 +344,8 @@ export default class BootstrapCommand extends Command {

// Link binaries into dependent packages so npm scripts will have
// access to them.
async.series(root.map(({name, dependents}) => (cb) => {
const {bin} = (this.hoistedPackageJson(name) || {});
async.series(root.map(({ name, dependents }) => (cb) => {
const { bin } = (this.hoistedPackageJson(name) || {});
if (bin) {
async.series(dependents.map((pkg) => (cb) => {
const src = this.hoistedDirectory(name);
Expand All @@ -362,8 +365,8 @@ export default class BootstrapCommand extends Command {
// Remove any hoisted dependencies that may have previously been
// installed in package directories.
actions.push((cb) => {
async.series(root.map(({name, dependents}) => (cb) => {
async.series(dependents.map(({nodeModulesLocation: dir}) => (cb) => {
async.series(root.map(({ name, dependents }) => (cb) => {
async.series(dependents.map(({ nodeModulesLocation: dir }) => (cb) => {
if (dir === this.repository.nodeModulesLocation) return cb();
FileSystemUtilities.rimraf(path.join(dir, name), cb);
}), cb);
Expand All @@ -376,15 +379,15 @@ export default class BootstrapCommand extends Command {

// Install anything that needs to go into the leaves.
Object.keys(leaves)
.map((pkgName) => ({pkg: this.packageGraph.get(pkgName).package, deps: leaves[pkgName]}))
.forEach(({pkg, deps}) => {
.map((pkgName) => ({ pkg: this.packageGraph.get(pkgName).package, deps: leaves[pkgName] }))
.forEach(({ pkg, deps }) => {

// If we have any unsatisfied deps then we need to install everything.
// This is important for consistent behavior across npm clients.
if (deps.some(({isSatisfied}) => !isSatisfied)) {
if (deps.some(({ isSatisfied }) => !isSatisfied)) {
actions.push(
(cb) => NpmUtilities.installInDir(
pkg.location, deps.map(({dependency}) => dependency), this.npmConfig, (err) => {
pkg.location, deps.map(({ dependency }) => dependency), this.npmConfig, (err) => {
this.progressBar.tick(pkg.name);
cb(err);
}
Expand Down Expand Up @@ -438,7 +441,10 @@ export default class BootstrapCommand extends Command {
);
} else {
// get the destination directory name of the dependency
const pkgDependencyLocation = path.join(filteredPackage.nodeModulesLocation, dependencyPackage.name);
const pkgDependencyLocation = path.join(
filteredPackage.nodeModulesLocation,
dependencyPackage.name
);
// check if dependency is already installed
if (FileSystemUtilities.existsSync(pkgDependencyLocation)) {
const isDepSymlink = FileSystemUtilities.isSymlink(pkgDependencyLocation);
Expand Down Expand Up @@ -470,7 +476,13 @@ export default class BootstrapCommand extends Command {
if (dependencyPackageJson.bin) {
const destFolder = filteredPackage.nodeModulesLocation;
packageActions.push((cb) => {
this.createBinaryLink(dependencyLocation, destFolder, dependency, dependencyPackageJson.bin, cb);
this.createBinaryLink(
dependencyLocation,
destFolder,
dependency,
dependencyPackageJson.bin,
cb
);
});
}
}
Expand Down

0 comments on commit c2fbcb2

Please sign in to comment.