Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/generate-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var yeoman = require("yeoman-environment");
var LoaderGenerator = require("../generators/loader-generator").LoaderGenerator;
const yeoman = require("yeoman-environment");
const { LoaderGenerator } = require("../generators/loader-generator");

/**
* Runs a yeoman generator to create a new webpack loader project
* @returns {void}
*/
function loaderCreator() {
var env = yeoman.createEnv();
var generatorName = "webpack-loader-generator";
const env = yeoman.createEnv();
const generatorName = "webpack-loader-generator";

env.registerStub(LoaderGenerator, generatorName);

Expand Down
8 changes: 4 additions & 4 deletions lib/generate-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var yeoman = require("yeoman-environment");
var PluginGenerator = require("../generators/plugin-generator").PluginGenerator;
const yeoman = require("yeoman-environment");
const PluginGenerator = require("../generators/plugin-generator").PluginGenerator;

@dhruvdutt dhruvdutt Mar 9, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change to const { PluginGenerator } here as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ES6 destructing now? Cool!


/**
* Runs a yeoman generator to create a new webpack plugin project
* @returns {void}
*/
function pluginCreator() {
var env = yeoman.createEnv();
var generatorName = "webpack-plugin-generator";
const env = yeoman.createEnv();
const generatorName = "webpack-plugin-generator";

env.registerStub(PluginGenerator, generatorName);

Expand Down
8 changes: 4 additions & 4 deletions lib/generators/loader-generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require("path");
var _ = require("lodash");
var webpackGenerator = require("./webpack-generator");
const path = require("path");
const _ = require("lodash");
const webpackGenerator = require("./webpack-generator");

/**
* Formats a string into webpack loader format
Expand All @@ -25,7 +25,7 @@ function makeLoaderName(name) {
* @class LoaderGenerator
* @extends {Generator}
*/
var LoaderGenerator = webpackGenerator(
const LoaderGenerator = webpackGenerator(
[
{
type: "input",
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/loader-generator.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";

var makeLoaderName = require("./loader-generator").makeLoaderName;
const makeLoaderName = require("./loader-generator").makeLoaderName;

describe("makeLoaderName", () => {
it("should kebab-case loader name and append '-loader'", () => {
var loaderName = makeLoaderName("This is a test");
const loaderName = makeLoaderName("This is a test");
expect(loaderName).toEqual("this-is-a-test-loader");
});

it("should not modify a properly formatted loader name", () => {
var loaderName = makeLoaderName("properly-named-loader");
const loaderName = makeLoaderName("properly-named-loader");
expect(loaderName).toEqual("properly-named-loader");
});
});
8 changes: 4 additions & 4 deletions lib/generators/plugin-generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require("path");
var _ = require("lodash");
var webpackGenerator = require("./webpack-generator");
const path = require("path");
const _ = require("lodash");
const webpackGenerator = require("./webpack-generator");

/**
* A yeoman generator class for creating a webpack
Expand All @@ -10,7 +10,7 @@ var webpackGenerator = require("./webpack-generator");
* @class PluginGenerator
* @extends {Generator}
*/
var PluginGenerator = webpackGenerator(
const PluginGenerator = webpackGenerator(
[
{
type: "input",
Expand Down
12 changes: 6 additions & 6 deletions lib/generators/webpack-generator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var path = require("path");
var mkdirp = require("mkdirp");
var Generator = require("yeoman-generator");
var copyUtils = require("../utils/copy-utils");
const path = require("path");
const mkdirp = require("mkdirp");
const Generator = require("yeoman-generator");
const copyUtils = require("../utils/copy-utils");

/**
* Creates a Yeoman Generator that generates a project conforming
Expand Down Expand Up @@ -40,14 +40,14 @@ function webpackGenerator(
}

default() {
var currentDirName = path.basename(this.destinationPath());
const currentDirName = path.basename(this.destinationPath());
if (currentDirName !== this.props.name) {
this.log(`
Your project must be inside a folder named ${this.props.name}
I will create this folder for you.
`);
mkdirp(this.props.name);
var pathToProjectDir = this.destinationPath(this.props.name);
const pathToProjectDir = this.destinationPath(this.props.name);
this.destinationRoot(pathToProjectDir);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`top-scope transforms correctly using "top-scope-0" data 1`] = `
"var test = 'me';
"const test = 'me';
module.exports = {}
"
`;
Expand Down
2 changes: 1 addition & 1 deletion lib/init/transformations/top-scope/top-scope.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const defineTest = require("../../../utils/defineTest");

defineTest(__dirname, "top-scope", "top-scope-0", ["var test = 'me';"], "init");
defineTest(__dirname, "top-scope", "top-scope-0", ["const test = 'me';"], "init");
defineTest(
__dirname,
"top-scope",
Expand Down
8 changes: 4 additions & 4 deletions lib/migrate/__testfixtures__/failing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var webpack = require("webpack");
var nodeEnvironment = process.env.NODE_ENV;
var _ = require("lodash");
const webpack = require("webpack");
const nodeEnvironment = process.env.NODE_ENV;
const _ = require("lodash");

var config = {
const config = {
entry: {
lib: "./app/index.js",
email: "./app/email.js"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function createOrUpdatePluginByName(j, rootNodePath, pluginName, options) {
* @param {any} j — jscodeshift API
* @param {Node} rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
* @param {String} pluginPackageName - ex. `extract-text-plugin`
* @returns {String} variable name - ex. 'var s = require(s) gives "s"`
* @returns {String} variable name - ex. 'const s = require(s) gives "s"`
*/

function findVariableToPlugin(j, rootNode, pluginPackageName) {
Expand Down
16 changes: 8 additions & 8 deletions lib/utils/ast-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe("utils", () => {
describe("findRootNodesByName", () => {
it("should find plugins: [] nodes", () => {
const ast = j(`
var a = { plugins: [], foo: { plugins: [] } }
const a = { plugins: [], foo: { plugins: [] } }
`);
const res = utils.findRootNodesByName(j, ast, "plugins");
expect(res.size()).toEqual(2);
});

it("should not find plugins: [] nodes", () => {
const ast = j(`
var a = { plugs: [] }
const a = { plugs: [] }
`);
const res = utils.findRootNodesByName(j, ast, "plugins");
expect(res.size()).toEqual(0);
Expand Down Expand Up @@ -132,12 +132,12 @@ var a = { plugs: [] }
describe("findVariableToPlugin", () => {
it("should find the variable name of a plugin", () => {
const ast = j(`
var packageName = require('package-name');
var someOtherVar = somethingElse;
var otherPackage = require('other-package');
const packageName = require('package-name');
const someOtherconst = somethingElse;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someOtherconst => someOtherConst

const otherPackage = require('other-package');
`);
const foundVar = utils.findVariableToPlugin(j, ast, "other-package");
expect(foundVar).toEqual("otherPackage");
const found = utils.findVariableToPlugin(j, ast, "other-package");
expect(found).toEqual("otherPackage");
});
});

Expand Down Expand Up @@ -166,7 +166,7 @@ var a = { plugs: [] }
describe("findObjWithOneOfKeys", () => {
it("should find keys", () => {
const ast = j(`
var ab = {
const ab = {
a: 1,
b: 2
}
Expand Down
14 changes: 7 additions & 7 deletions lib/utils/copy-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var path = require("path");
const path = require("path");

/**
* Takes in a file path in the `./templates` directory. Copies that
Expand All @@ -8,13 +8,13 @@ var path = require("path");
* @param {string} templateDir Absolute path to template directory
* @returns {Function} A curried function that takes a file path and copies it
*/
var generatorCopy = (
const generatorCopy = (
generator,
templateDir
) => /** @param {string} filePath */ filePath => {
var sourceParts = templateDir.split(path.delimiter);
const sourceParts = templateDir.split(path.delimiter);
sourceParts.push.apply(sourceParts, filePath.split("/"));
var targetParts = path.dirname(filePath).split("/");
const targetParts = path.dirname(filePath).split("/");
targetParts.push(path.basename(filePath, ".tpl"));

generator.fs.copy(
Expand All @@ -34,14 +34,14 @@ var generatorCopy = (
* the template files.
* @returns {Function} A curried function that takes a file path and copies it
*/
var generatorCopyTpl = (
const generatorCopyTpl = (
generator,
templateDir,
templateData
) => /** @param {string} filePath */ filePath => {
var sourceParts = templateDir.split(path.delimiter);
const sourceParts = templateDir.split(path.delimiter);
sourceParts.push.apply(sourceParts, filePath.split("/"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutable object, but okay..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't get reassigned, so const is ok. Otherwise eslint would have failed :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .push method is mutating it, ( even though the push method is immutable ) but that's another thing :D

var targetParts = path.dirname(filePath).split("/");
const targetParts = path.dirname(filePath).split("/");
targetParts.push(path.basename(filePath, ".tpl").slice(1));

generator.fs.copyTpl(
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/hashtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* @returns {Array} A sorted array with removed dupe elements
*/
module.exports = function hashtable(a) {
var prims = { boolean: {}, number: {}, string: {} },
const prims = { boolean: {}, number: {}, string: {} },
objs = [];

return a.filter(function(item) {
var type = typeof item;
const type = typeof item;
if (type in prims)
return prims[type].hasOwnProperty(item)
? false
Expand Down