Run new lint rules (#5413)

This commit is contained in:
Brian Ng
2017-03-04 09:46:01 -06:00
committed by Henry Zhu
parent f7e2d88f6c
commit 8a82cc060a
181 changed files with 1459 additions and 1454 deletions

View File

@@ -17,7 +17,7 @@ export default class Store {
return this._map.get(key);
} else {
if (Object.prototype.hasOwnProperty.call(this._map.dynamicData, key)) {
const val = this._map.dynamicData[key]();
const val = this._map.dynamicData[key]();
this._map.set(key, val);
return val;
}

View File

@@ -19,9 +19,9 @@ const buildUmdWrapper = template(`
`);
function buildGlobal(namespace, builder) {
const body = [];
const body = [];
const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
const tree = t.program([
const tree = t.program([
t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
body.push(t.variableDeclaration("var", [
@@ -29,7 +29,7 @@ function buildGlobal(namespace, builder) {
namespace,
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace),
t.objectExpression([]))
)
),
]));
builder(body);
@@ -40,7 +40,7 @@ function buildGlobal(namespace, builder) {
function buildUmd(namespace, builder) {
const body = [];
body.push(t.variableDeclaration("var", [
t.variableDeclarator(namespace, t.identifier("global"))
t.variableDeclarator(namespace, t.identifier("global")),
]));
builder(body);
@@ -48,23 +48,23 @@ function buildUmd(namespace, builder) {
return t.program([
buildUmdWrapper({
FACTORY_PARAMETERS: t.identifier("global"),
BROWSER_ARGUMENTS: t.assignmentExpression(
BROWSER_ARGUMENTS: t.assignmentExpression(
"=",
t.memberExpression(t.identifier("root"), namespace),
t.objectExpression([])
),
COMMON_ARGUMENTS: t.identifier("exports"),
AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
FACTORY_BODY: body,
UMD_ROOT: t.identifier("this")
})
COMMON_ARGUMENTS: t.identifier("exports"),
AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
FACTORY_BODY: body,
UMD_ROOT: t.identifier("this"),
}),
]);
}
function buildVar(namespace, builder) {
const body = [];
body.push(t.variableDeclaration("var", [
t.variableDeclarator(namespace, t.objectExpression([]))
t.variableDeclarator(namespace, t.objectExpression([])),
]));
builder(body);
body.push(t.expressionStatement(namespace));
@@ -95,8 +95,8 @@ export default function (
const build = {
global: buildGlobal,
umd: buildUmd,
var: buildVar,
umd: buildUmd,
var: buildVar,
}[outputType];
if (build) {

View File

@@ -14,7 +14,7 @@ import traverse from "babel-traverse";
import Logger from "./logger";
import Store from "../../store";
import { parse } from "babylon";
import * as util from "../../util";
import * as util from "../../util";
import path from "path";
import * as t from "babel-types";
@@ -27,7 +27,7 @@ const shebangRegex = /^#!.*/;
const INTERNAL_PLUGINS = [
[blockHoistPlugin],
[shadowFunctionsPlugin]
[shadowFunctionsPlugin],
];
const errorVisitor = {
@@ -37,20 +37,20 @@ const errorVisitor = {
state.loc = loc;
path.stop();
}
}
},
};
export default class File extends Store {
constructor(opts: Object = {}) {
super();
this.log = new Logger(this, opts.filename || "unknown");
this.log = new Logger(this, opts.filename || "unknown");
this.opts = this.initOptions(opts);
this.parserOpts = {
sourceType: this.opts.sourceType,
sourceType: this.opts.sourceType,
sourceFileName: this.opts.filename,
plugins: []
plugins: [],
};
this.pluginVisitors = [];
@@ -78,21 +78,21 @@ export default class File extends Store {
imports: [],
exports: {
exported: [],
specifiers: []
}
}
specifiers: [],
},
},
};
this.dynamicImportTypes = {};
this.dynamicImportIds = {};
this.dynamicImports = [];
this.declarations = {};
this.usedHelpers = {};
this.dynamicImportIds = {};
this.dynamicImports = [];
this.declarations = {};
this.usedHelpers = {};
this.path = null;
this.ast = {};
this.ast = {};
this.code = "";
this.code = "";
this.shebang = "";
this.hub = new Hub(this);
@@ -149,22 +149,22 @@ export default class File extends Store {
if (opts.only) opts.only = util.arrayify(opts.only, util.regexify);
defaults(opts, {
moduleRoot: opts.sourceRoot
moduleRoot: opts.sourceRoot,
});
defaults(opts, {
sourceRoot: opts.moduleRoot
sourceRoot: opts.moduleRoot,
});
defaults(opts, {
filenameRelative: opts.filename
filenameRelative: opts.filename,
});
const basenameRelative = path.basename(opts.filenameRelative);
defaults(opts, {
sourceFileName: basenameRelative,
sourceMapTarget: basenameRelative
sourceFileName: basenameRelative,
sourceMapTarget: basenameRelative,
});
return opts;
@@ -282,7 +282,7 @@ export default class File extends Store {
}
const generator = this.get("helperGenerator");
const runtime = this.get("helpersNamespace");
const runtime = this.get("helpersNamespace");
if (generator) {
const res = generator(name);
if (res) return res;
@@ -304,7 +304,7 @@ export default class File extends Store {
this.scope.push({
id: uid,
init: ref,
unique: true
unique: true,
});
}
@@ -334,7 +334,7 @@ export default class File extends Store {
this.scope.push({
id: uid,
init: init,
_blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
_blockHoist: 1.9, // This ensures that we don't fail if not using function expression helpers
});
return uid;
}
@@ -365,12 +365,12 @@ export default class File extends Store {
const inputMap = this.opts.inputSourceMap;
if (inputMap) {
const inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
const outputMapConsumer = new sourceMap.SourceMapConsumer(map);
const inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
const outputMapConsumer = new sourceMap.SourceMapConsumer(map);
const mergedGenerator = new sourceMap.SourceMapGenerator({
file: inputMapConsumer.file,
sourceRoot: inputMapConsumer.sourceRoot
sourceRoot: inputMapConsumer.sourceRoot,
});
// This assumes the output map always has a single source, since Babel always compiles a
@@ -381,7 +381,7 @@ export default class File extends Store {
const generatedPosition = outputMapConsumer.generatedPositionFor({
line: mapping.generatedLine,
column: mapping.generatedColumn,
source: source
source: source,
});
if (generatedPosition.column != null) {
mergedGenerator.addMapping({
@@ -389,10 +389,10 @@ export default class File extends Store {
original: mapping.source == null ? null : {
line: mapping.originalLine,
column: mapping.originalColumn
column: mapping.originalColumn,
},
generated: generatedPosition
generated: generatedPosition,
});
}
});
@@ -429,7 +429,7 @@ export default class File extends Store {
parserOpts.parser = {
parse(source) {
return parse(source, parserOpts);
}
},
};
}
}
@@ -446,10 +446,10 @@ export default class File extends Store {
parentPath: null,
parent: ast,
container: ast,
key: "program"
key: "program",
}).setContext();
this.scope = this.path.scope;
this.ast = ast;
this.ast = ast;
this.getMetadata();
}
@@ -568,11 +568,11 @@ export default class File extends Store {
makeResult({ code, map, ast, ignored }: BabelFileResult): BabelFileResult {
const result = {
metadata: null,
options: this.opts,
ignored: !!ignored,
code: null,
ast: null,
map: map || null
options: this.opts,
ignored: !!ignored,
code: null,
ast: null,
map: map || null,
};
if (this.opts.code) {
@@ -592,7 +592,7 @@ export default class File extends Store {
generate(): BabelFileResult {
const opts = this.opts;
const ast = this.ast;
const ast = this.ast;
const result: BabelFileResult = { ast };
if (!opts.code) return this.makeResult(result);
@@ -618,7 +618,7 @@ export default class File extends Store {
const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts,
this.code);
result.code = _result.code;
result.map = _result.map;
result.map = _result.map;
this.log.debug("Generation end");

View File

@@ -9,7 +9,7 @@ const seenDeprecatedMessages = [];
export default class Logger {
constructor(file: File, filename: string) {
this.filename = filename;
this.file = file;
this.file = file;
}
filename: string;

View File

@@ -6,7 +6,7 @@ export const ModuleDeclaration = {
if (node.source) {
node.source.value = file.resolveModuleSource(node.source.value);
}
}
},
};
export const ImportDeclaration = {
@@ -18,7 +18,7 @@ export const ImportDeclaration = {
file.metadata.modules.imports.push({
source: node.source.value,
imported,
specifiers
specifiers,
});
for (const specifier of (path.get("specifiers"): Array<Object>)) {
@@ -29,7 +29,7 @@ export const ImportDeclaration = {
specifiers.push({
kind: "named",
imported: "default",
local
local,
});
}
@@ -39,7 +39,7 @@ export const ImportDeclaration = {
specifiers.push({
kind: "named",
imported: importedName,
local
local,
});
}
@@ -47,11 +47,11 @@ export const ImportDeclaration = {
imported.push("*");
specifiers.push({
kind: "namespace",
local
local,
});
}
}
}
},
};
export function ExportDeclaration(path, file) {
@@ -71,7 +71,7 @@ export function ExportDeclaration(path, file) {
exports.specifiers.push({
kind: "local",
local: name,
exported: path.isExportDefaultDeclaration() ? "default" : name
exported: path.isExportDefaultDeclaration() ? "default" : name,
});
}
}
@@ -87,7 +87,7 @@ export function ExportDeclaration(path, file) {
kind: "external",
local: exported,
exported,
source
source,
});
}
@@ -96,7 +96,7 @@ export function ExportDeclaration(path, file) {
exports.specifiers.push({
kind: "external-namespace",
exported,
source
source,
});
}
@@ -110,7 +110,7 @@ export function ExportDeclaration(path, file) {
kind: "external",
local: local.name,
exported,
source
source,
});
}
@@ -120,7 +120,7 @@ export function ExportDeclaration(path, file) {
exports.specifiers.push({
kind: "local",
local: local.name,
exported
exported,
});
}
}
@@ -130,7 +130,7 @@ export function ExportDeclaration(path, file) {
if (path.isExportAllDeclaration()) {
exports.specifiers.push({
kind: "external-all",
source
source,
});
}
}

View File

@@ -6,11 +6,11 @@ import path from "path";
import fs from "fs";
const existsCache = {};
const jsonCache = {};
const jsonCache = {};
const BABELIGNORE_FILENAME = ".babelignore";
const BABELRC_FILENAME = ".babelrc";
const PACKAGE_FILENAME = "package.json";
const BABELRC_FILENAME = ".babelrc";
const PACKAGE_FILENAME = "package.json";
function exists(filename) {
const cached = existsCache[filename];
@@ -33,7 +33,7 @@ export default function buildConfigChain(opts: Object = {}, log?: Logger) {
builder.mergeConfig({
options: opts,
alias: "base",
dirname: filename && path.dirname(filename)
dirname: filename && path.dirname(filename),
});
return builder.configs;
@@ -83,7 +83,7 @@ class ConfigChainBuilder {
}
addIgnoreConfig(loc) {
const file = fs.readFileSync(loc, "utf8");
const file = fs.readFileSync(loc, "utf8");
let lines = file.split("\n");
lines = lines
@@ -94,7 +94,7 @@ class ConfigChainBuilder {
this.mergeConfig({
options: { ignore: lines },
alias: loc,
dirname: path.dirname(loc)
dirname: path.dirname(loc),
});
}
}
@@ -120,7 +120,7 @@ class ConfigChainBuilder {
this.mergeConfig({
options,
alias: loc,
dirname: path.dirname(loc)
dirname: path.dirname(loc),
});
return !!options;
@@ -130,7 +130,7 @@ class ConfigChainBuilder {
options,
alias,
loc,
dirname
dirname,
}) {
if (!options) {
return false;
@@ -156,7 +156,7 @@ class ConfigChainBuilder {
options,
alias,
loc,
dirname
dirname,
});
// env
@@ -170,7 +170,7 @@ class ConfigChainBuilder {
this.mergeConfig({
options: envOpts,
alias: `${alias}.env.${envKey}`,
dirname: dirname
dirname: dirname,
});
}
}

View File

@@ -5,191 +5,191 @@ export default {
type: "filename",
description: "filename to use when reading from stdin - this will be used in source-maps, errors etc",
default: "unknown",
shorthand: "f"
shorthand: "f",
},
filenameRelative: {
hidden: true,
type: "string"
type: "string",
},
inputSourceMap: {
hidden: true
hidden: true,
},
env: {
hidden: true,
default: {}
default: {},
},
mode: {
description: "",
hidden: true
hidden: true,
},
retainLines: {
type: "boolean",
default: false,
description: "retain line numbers - will result in really ugly code"
description: "retain line numbers - will result in really ugly code",
},
highlightCode: {
description: "enable/disable ANSI syntax highlighting of code frames (on by default)",
type: "boolean",
default: true
default: true,
},
suppressDeprecationMessages: {
type: "boolean",
default: false,
hidden: true
hidden: true,
},
presets: {
type: "list",
description: "",
default: []
default: [],
},
plugins: {
type: "list",
default: [],
description: ""
description: "",
},
ignore: {
type: "list",
description: "list of glob paths to **not** compile",
default: []
default: [],
},
only: {
type: "list",
description: "list of glob paths to **only** compile"
description: "list of glob paths to **only** compile",
},
code: {
hidden: true,
default: true,
type: "boolean"
type: "boolean",
},
metadata: {
hidden: true,
default: true,
type: "boolean"
type: "boolean",
},
ast: {
hidden: true,
default: true,
type: "boolean"
type: "boolean",
},
extends: {
type: "string",
hidden: true
hidden: true,
},
comments: {
type: "boolean",
default: true,
description: "write comments to generated output (true by default)"
description: "write comments to generated output (true by default)",
},
shouldPrintComment: {
hidden: true,
description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored"
description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored",
},
wrapPluginVisitorMethod: {
hidden: true,
description: "optional callback to wrap all visitor methods"
description: "optional callback to wrap all visitor methods",
},
compact: {
type: "booleanString",
default: "auto",
description: "do not include superfluous whitespace characters and line terminators [true|false|auto]"
description: "do not include superfluous whitespace characters and line terminators [true|false|auto]",
},
minified: {
type: "boolean",
default: false,
description: "save as much bytes when printing [true|false]"
description: "save as much bytes when printing [true|false]",
},
sourceMap: {
alias: "sourceMaps",
hidden: true
hidden: true,
},
sourceMaps: {
type: "booleanString",
description: "[true|false|inline]",
default: false,
shorthand: "s"
shorthand: "s",
},
sourceMapTarget: {
type: "string",
description: "set `file` on returned source map"
description: "set `file` on returned source map",
},
sourceFileName: {
type: "string",
description: "set `sources[0]` on returned source map"
description: "set `sources[0]` on returned source map",
},
sourceRoot: {
type: "filename",
description: "the root from which all sources are relative"
description: "the root from which all sources are relative",
},
babelrc: {
description: "Whether or not to look up .babelrc and .babelignore files",
type: "boolean",
default: true
default: true,
},
sourceType: {
description: "",
default: "module"
default: "module",
},
auxiliaryCommentBefore: {
type: "string",
description: "print a comment before any injected non-user code"
description: "print a comment before any injected non-user code",
},
auxiliaryCommentAfter: {
type: "string",
description: "print a comment after any injected non-user code"
description: "print a comment after any injected non-user code",
},
resolveModuleSource: {
hidden: true
hidden: true,
},
getModuleId: {
hidden: true
hidden: true,
},
moduleRoot: {
type: "filename",
description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"
description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions",
},
moduleIds: {
type: "boolean",
default: false,
shorthand: "M",
description: "insert an explicit id for modules"
description: "insert an explicit id for modules",
},
moduleId: {
description: "specify a custom name for module ids",
type: "string"
type: "string",
},
passPerPreset: {
@@ -202,12 +202,12 @@ export default {
// Deprecate top level parserOpts
parserOpts: {
description: "Options to pass into the parser, or to change parsers (parserOpts.parser)",
default: false
default: false,
},
// Deprecate top level generatorOpts
generatorOpts: {
description: "Options to pass into the generator, or to change generators (generatorOpts.generator)",
default: false
}
default: false,
},
};

View File

@@ -67,7 +67,7 @@ export default class OptionManager {
const plugin = new Plugin(obj, alias);
OptionManager.memoisedPlugins.push({
container: fn,
plugin: plugin
plugin: plugin,
});
return plugin;
} else {
@@ -151,7 +151,7 @@ export default class OptionManager {
extending: extendingOpts,
alias,
loc,
dirname
dirname,
}: MergeOptions) {
alias = alias || "foreign";
if (!rawOpts) return;
@@ -208,7 +208,7 @@ export default class OptionManager {
extending: preset,
alias: presetLoc,
loc: presetLoc,
dirname: dirname
dirname: dirname,
});
});
} else {
@@ -238,7 +238,7 @@ export default class OptionManager {
options: presetOpts,
alias: presetLoc,
loc: presetLoc,
dirname: path.dirname(presetLoc || "")
dirname: path.dirname(presetLoc || ""),
});
});
}
@@ -318,7 +318,7 @@ export default class OptionManager {
for (const key in config) {
const option = config[key];
const val = opts[key];
const val = opts[key];
// optional
if (!val && option.optional) continue;

View File

@@ -2,34 +2,34 @@
export default {
"auxiliaryComment": {
"message": "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`"
"message": "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`",
},
"blacklist": {
"message": "Put the specific transforms you want in the `plugins` option"
"message": "Put the specific transforms you want in the `plugins` option",
},
"breakConfig": {
"message": "This is not a necessary option in Babel 6"
"message": "This is not a necessary option in Babel 6",
},
"experimental": {
"message": "Put the specific transforms you want in the `plugins` option"
"message": "Put the specific transforms you want in the `plugins` option",
},
"externalHelpers": {
"message": "Use the `external-helpers` plugin instead. Check out http://babeljs.io/docs/plugins/external-helpers/"
"message": "Use the `external-helpers` plugin instead. Check out http://babeljs.io/docs/plugins/external-helpers/",
},
"extra": {
"message": ""
"message": "",
},
"jsxPragma": {
"message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/"
"message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/",
},
// "keepModuleIdExtensions": {
// "message": ""
// },
"loose": {
"message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option."
"message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option.",
},
"metadataUsedHelpers": {
"message": "Not required anymore as this is enabled by default"
"message": "Not required anymore as this is enabled by default",
},
"modules": {
"message": "Use the corresponding module transform plugin in the `plugins` option. Check out http://babeljs.io/docs/plugins/#modules",
@@ -38,15 +38,15 @@ export default {
"message": "Use the `react-jsx` and `flow-strip-types` plugins to support JSX and Flow. Also check out the react preset http://babeljs.io/docs/plugins/preset-react/",
},
"optional": {
"message": "Put the specific transforms you want in the `plugins` option"
"message": "Put the specific transforms you want in the `plugins` option",
},
"sourceMapName": {
"message": "Use the `sourceMapTarget` option"
"message": "Use the `sourceMapTarget` option",
},
"stage": {
"message": "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets"
"message": "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets",
},
"whitelist": {
"message": "Put the specific transforms you want in the `plugins` option"
}
"message": "Put the specific transforms you want in the `plugins` option",
},
};

View File

@@ -36,7 +36,7 @@ export default new Plugin({
// Higher priorities should move toward the top.
return -1 * priority;
});
}
}
}
},
},
},
});

View File

@@ -12,7 +12,7 @@ const superVisitor = {
node[SUPER_THIS_BOUND] = true;
path.replaceWith(t.assignmentExpression("=", this.id, node));
}
},
};
export default new Plugin({
@@ -27,8 +27,8 @@ export default new Plugin({
if (path.node.name === "arguments") {
remap(path, "arguments");
}
}
}
},
},
});
function shouldShadow(path, shadowPath) {
@@ -94,7 +94,7 @@ function remap(path, key) {
const cached = fnPath.getData(key);
if (cached) return path.replaceWith(cached);
const id = path.scope.generateUidIdentifier(key);
const id = path.scope.generateUidIdentifier(key);
fnPath.setData(key, id);

View File

@@ -6,9 +6,9 @@ export default class PluginPass extends Store {
constructor(file: File, plugin: Plugin, options: Object = {}) {
super();
this.plugin = plugin;
this.key = plugin.key;
this.file = file;
this.opts = options;
this.key = plugin.key;
this.file = file;
this.opts = options;
}
key: string;

View File

@@ -11,13 +11,13 @@ export default class Plugin extends Store {
super();
this.initialized = false;
this.raw = Object.assign({}, plugin);
this.key = this.take("name") || key;
this.raw = Object.assign({}, plugin);
this.key = this.take("name") || key;
this.manipulateOptions = this.take("manipulateOptions");
this.post = this.take("post");
this.pre = this.take("pre");
this.visitor = this.normaliseVisitor(clone(this.take("visitor")) || {});
this.post = this.take("post");
this.pre = this.take("pre");
this.visitor = this.normaliseVisitor(clone(this.take("visitor")) || {});
}
initialized: boolean;