tools: update ESLint to 5.14.0

Update ESLint to 5.14.0

PR-URL: https://github.com/nodejs/node/pull/26142
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
This commit is contained in:
cjihrig 2019-02-15 16:51:43 -05:00
parent 2da7ff5e96
commit 77b39c2eb2
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
184 changed files with 3212 additions and 3652 deletions

224
tools/node_modules/eslint/README.md generated vendored
View File

@ -197,170 +197,82 @@ These folks keep the project moving and are resources for help.
The people who manage releases, review feature requests, and meet regularly to ensure ESLint is properly maintained.
<table>
<tbody>
<tr>
<td align="center" valign="top" width="11%">
<a href="https://github.com/nzakas">
<img src="https://github.com/nzakas.png?s=75" width="75px" height="75px"><br/>
<sub>Nicholas C. Zakas</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/ilyavolodin">
<img src="https://github.com/ilyavolodin.png?s=75" width="75px" height="75px"><br/>
<sub>Ilya Volodin</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/btmills">
<img src="https://github.com/btmills.png?s=75" width="75px" height="75px"><br/>
<sub>Brandon Mills</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/gyandeeps">
<img src="https://github.com/gyandeeps.png?s=75" width="75px" height="75px"><br/>
<sub>Gyandeep Singh</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/mysticatea">
<img src="https://github.com/mysticatea.png?s=75" width="75px" height="75px"><br/>
<sub>Toru Nagashima</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/alberto">
<img src="https://github.com/alberto.png?s=75" width="75px" height="75px"><br/>
<sub>Alberto Rodríguez</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/kaicataldo">
<img src="https://github.com/kaicataldo.png?s=75" width="75px" height="75px"><br/>
<sub>Kai Cataldo</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/not-an-aardvark">
<img src="https://github.com/not-an-aardvark.png?s=75" width="75px" height="75px"><br/>
<sub>Teddy Katz</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/platinumazure">
<img src="https://github.com/platinumazure.png?s=75" width="75px" height="75px"><br/>
<sub>Kevin Partington</sub></a>
</td>
</tr>
</tbody>
</table>
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
<!--tscstart-->
<table><tbody><tr><td align="center" valign="top" width="11%">
<a href="https://github.com/nzakas">
<img src="https://github.com/nzakas.png?s=75" width="75" height="75"><br />
Nicholas C. Zakas
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/platinumazure">
<img src="https://github.com/platinumazure.png?s=75" width="75" height="75"><br />
Kevin Partington
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/ilyavolodin">
<img src="https://github.com/ilyavolodin.png?s=75" width="75" height="75"><br />
Ilya Volodin
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/btmills">
<img src="https://github.com/btmills.png?s=75" width="75" height="75"><br />
Brandon Mills
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/mysticatea">
<img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
Toru Nagashima
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/gyandeeps">
<img src="https://github.com/gyandeeps.png?s=75" width="75" height="75"><br />
Gyandeep Singh
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/kaicataldo">
<img src="https://github.com/kaicataldo.png?s=75" width="75" height="75"><br />
Kai Cataldo
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/not-an-aardvark">
<img src="https://github.com/not-an-aardvark.png?s=75" width="75" height="75"><br />
Teddy Katz
</a>
</td></tr></tbody></table><!--tscend-->
### Committers
The people who review and fix bugs and help triage issues.
<table>
<tbody>
<tr>
<td align="center" valign="top" width="11%">
<a href="https://github.com/Aladdin-ADD">
<img src="https://github.com/Aladdin-ADD.png?s=75" width="75px" height="75px"><br/>
<sub>薛定谔的猫</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/g-plane">
<img src="https://github.com/g-plane.png?s=75" width="75px" height="75px"><br/>
<sub>Pig Fang</sub></a>
</td>
</tr>
</tbody>
</table>
### Alumni
Former TSC members and committers who previously helped maintain ESLint.
<table>
<tbody>
<tr>
<td align="center" valign="top" width="11%">
<a href="https://github.com/lo1tuma">
<img src="https://github.com/lo1tuma.png?s=75" width="75px" height="75px"><br/>
<sub>Mathias Schreck</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/xjamundx">
<img src="https://github.com/xjamundx.png?s=75" width="75px" height="75px"><br/>
<sub>Jamund Ferguson</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/ianvs">
<img src="https://github.com/ianvs.png?s=75" width="75px" height="75px"><br/>
<sub>Ian VanSchooten</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/byk">
<img src="https://github.com/byk.png?s=75" width="75px" height="75px"><br/>
<sub>Burak Yiğit Kaya</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/michaelficarra">
<img src="https://github.com/michaelficarra.png?s=75" width="75px" height="75px"><br/>
<sub>Michael Ficarra</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/pedrottimark">
<img src="https://github.com/pedrottimark.png?s=75" width="75px" height="75px"><br/>
<sub>Mark Pedrotti</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/markelog">
<img src="https://github.com/markelog.png?s=75" width="75px" height="75px"><br/>
<sub>Oleg Gaidarenko</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/mikesherov">
<img src="https://github.com/mikesherov.png?s=75" width="75px" height="75px"><br/>
<sub>Mike Sherov</sub></a>
</td>
</tr>
<tr>
<td align="center" valign="top" width="11%">
<a href="https://github.com/hzoo">
<img src="https://github.com/hzoo.png?s=75" width="75px" height="75px"><br/>
<sub>Henry Zhu</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/mdevils">
<img src="https://github.com/mdevils.png?s=75" width="75px" height="75px"><br/>
<sub>Marat Dulin</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/zxqfox">
<img src="https://github.com/zxqfox.png?s=75" width="75px" height="75px"><br/>
<sub>Alexej Yaroshevich</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/vitorbal">
<img src="https://github.com/vitorbal.png?s=75" width="75px" height="75px"><br/>
<sub>Vitor Balocco</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/JamesHenry">
<img src="https://github.com/JamesHenry.png?s=75" width="75px" height="75px"><br/>
<sub>James Henry</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/soda0289">
<img src="https://github.com/soda0289.png?s=75" width="75px" height="75px"><br/>
<sub>Reyad Attiyat</sub></a>
</td>
<td align="center" valign="top" width="11%">
<a href="https://github.com/VictorHom">
<img src="https://github.com/VictorHom.png?s=75" width="75px" height="75px"><br/>
<sub>Victor Hom</sub></a>
</td>
</tr>
</tbody>
</table>
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
<!--committersstart-->
<table><tbody><tr><td align="center" valign="top" width="11%">
<a href="https://github.com/aladdin-add">
<img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />
薛定谔的猫
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/g-plane">
<img src="https://github.com/g-plane.png?s=75" width="75" height="75"><br />
Pig Fang
</a>
</td></tr></tbody></table><!--committersend-->
## Sponsors
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://opencollective.com/eslint) to get your logo on our README and website.
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
<!--sponsorsstart-->
<h3>Gold Sponsors</h3>
<p><a href="https://code.facebook.com/projects/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fres.cloudinary.com%2Fopencollective%2Fimage%2Fupload%2Fv1508519428%2FS9gk78AS_400x400_fulq2l.jpg&height=96" alt="Facebook Open Source" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F098e3bd0-4d57-11e8-9324-0f6cc1f92bf1.png&height=96" alt="Airbnb" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F68ed8b70-ebf2-11e6-9958-cb7e79408c56.png&height=96" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="http://faithlife.com/ref/about"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Ffaithlife.com&height=96" alt="Faithlife" height="32"></a></p>
<!--sponsorsend-->
## Technology Sponsors
* Site search ([eslint.org](https://eslint.org)) is sponsored by [Algolia](https://www.algolia.com)

View File

@ -455,6 +455,9 @@ class CLIEngine {
if (this.options.rules && Object.keys(this.options.rules).length) {
const loadedRules = this.linter.getRules();
// Ajv validator with default schema will mutate original object, so we must clone it recursively.
this.options.rules = lodash.cloneDeep(this.options.rules);
Object.keys(this.options.rules).forEach(name => {
validator.validateRuleOptions(loadedRules.get(name), name, this.options.rules[name], "CLI");
});

View File

@ -280,15 +280,38 @@ function writeYAMLConfigFile(config, filePath) {
* Writes a configuration file in JavaScript format.
* @param {Object} config The configuration object to write.
* @param {string} filePath The filename to write to.
* @throws {Error} If an error occurs linting the config file contents.
* @returns {void}
* @private
*/
function writeJSConfigFile(config, filePath) {
debug(`Writing JS config file: ${filePath}`);
const content = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })};`;
let contentToWrite;
const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })};`;
fs.writeFileSync(filePath, content, "utf8");
try {
const CLIEngine = require("../cli-engine");
const linter = new CLIEngine({
baseConfig: config,
fix: true,
useEslintrc: false
});
const report = linter.executeOnText(stringifiedContent);
contentToWrite = report.results[0].output || stringifiedContent;
} catch (e) {
debug("Error linting JavaScript config file, writing unlinted version");
const errorMessage = e.message;
contentToWrite = stringifiedContent;
e.message = "An error occurred while generating your JavaScript config file. ";
e.message += "A config file was still generated, but the config file itself may not follow your linting rules.";
e.message += `\nError: ${errorMessage}`;
throw e;
} finally {
fs.writeFileSync(filePath, contentToWrite, "utf8");
}
}
/**

View File

@ -3,6 +3,7 @@
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
@ -28,6 +29,8 @@ const debug = require("debug")("eslint:config-initializer");
// Private
//------------------------------------------------------------------------------
const DEFAULT_ECMA_VERSION = 2018;
/* istanbul ignore next: hard to test fs function */
/**
* Create .eslintrc file in the current working directory
@ -239,43 +242,65 @@ function configureRules(answers, config) {
* @returns {Object} config object
*/
function processAnswers(answers) {
let config = { rules: {}, env: {}, parserOptions: {} };
let config = {
rules: {},
env: {},
parserOptions: {},
extends: []
};
config.parserOptions.ecmaVersion = answers.ecmaVersion;
if (answers.ecmaVersion >= 2015) {
if (answers.modules) {
config.parserOptions.sourceType = "module";
}
config.env.es6 = true;
}
// set the latest ECMAScript version
config.parserOptions.ecmaVersion = DEFAULT_ECMA_VERSION;
config.env.es6 = true;
config.globals = {
Atomics: "readonly",
SharedArrayBuffer: "readonly"
};
if (answers.commonjs) {
// set the module type
if (answers.moduleType === "esm") {
config.parserOptions.sourceType = "module";
} else if (answers.moduleType === "commonjs") {
config.env.commonjs = true;
}
// add in browser and node environments if necessary
answers.env.forEach(env => {
config.env[env] = true;
});
if (answers.jsx) {
config.parserOptions = config.parserOptions || {};
config.parserOptions.ecmaFeatures = config.parserOptions.ecmaFeatures || {};
config.parserOptions.ecmaFeatures.jsx = true;
if (answers.react) {
config.plugins = ["react"];
config.parserOptions.ecmaVersion = 2018;
// add in library information
if (answers.framework === "react") {
config.parserOptions.ecmaFeatures = {
jsx: true
};
config.plugins = ["react"];
} else if (answers.framework === "vue") {
config.plugins = ["vue"];
config.extends.push("plugin:vue/essential");
}
// setup rules based on problems/style enforcement preferences
if (answers.purpose === "problems") {
config.extends.unshift("eslint:recommended");
} else if (answers.purpose === "style") {
if (answers.source === "prompt") {
config.extends.unshift("eslint:recommended");
config.rules.indent = ["error", answers.indent];
config.rules.quotes = ["error", answers.quotes];
config.rules["linebreak-style"] = ["error", answers.linebreak];
config.rules.semi = ["error", answers.semi ? "always" : "never"];
} else if (answers.source === "auto") {
config = configureRules(answers, config);
config = autoconfig.extendFromRecommended(config);
}
}
if (answers.source === "prompt") {
config.extends = "eslint:recommended";
config.rules.indent = ["error", answers.indent];
config.rules.quotes = ["error", answers.quotes];
config.rules["linebreak-style"] = ["error", answers.linebreak];
config.rules.semi = ["error", answers.semi ? "always" : "never"];
}
if (answers.source === "auto") {
config = configureRules(answers, config);
config = autoconfig.extendFromRecommended(config);
// normalize extends
if (config.extends.length === 0) {
delete config.extends;
} else if (config.extends.length === 1) {
config.extends = config.extends[0];
}
ConfigOps.normalizeToStrings(config);
@ -324,7 +349,7 @@ function getLocalESLintVersion() {
* @returns {string} The shareable config name.
*/
function getStyleGuideName(answers) {
if (answers.styleguide === "airbnb" && !answers.airbnbReact) {
if (answers.styleguide === "airbnb" && answers.framework !== "react") {
return "airbnb-base";
}
return answers.styleguide;
@ -417,16 +442,62 @@ function askInstallModules(modules, packageJsonExists) {
function promptUser() {
return inquirer.prompt([
{
type: "list",
name: "purpose",
message: "How would you like to use ESLint?",
default: "problems",
choices: [
{ name: "To check syntax only", value: "syntax" },
{ name: "To check syntax and find problems", value: "problems" },
{ name: "To check syntax, find problems, and enforce code style", value: "style" }
]
},
{
type: "list",
name: "moduleType",
message: "What type of modules does your project use?",
default: "esm",
choices: [
{ name: "JavaScript modules (import/export)", value: "esm" },
{ name: "CommonJS (require/exports)", value: "commonjs" },
{ name: "None of these", value: "none" }
]
},
{
type: "list",
name: "framework",
message: "Which framework does your project use?",
default: "react",
choices: [
{ name: "React", value: "react" },
{ name: "Vue.js", value: "vue" },
{ name: "None of these", value: "none" }
]
},
{
type: "checkbox",
name: "env",
message: "Where does your code run?",
default: ["browser"],
choices: [
{ name: "Browser", value: "browser" },
{ name: "Node", value: "node" }
]
},
{
type: "list",
name: "source",
message: "How would you like to configure ESLint?",
default: "prompt",
message: "How would you like to define a style for your project?",
default: "guide",
choices: [
{ name: "Use a popular style guide", value: "guide" },
{ name: "Answer questions about your style", value: "prompt" },
{ name: "Inspect your JavaScript file(s)", value: "auto" }
]
],
when(answers) {
return answers.purpose === "style";
}
},
{
type: "list",
@ -442,15 +513,6 @@ function promptUser() {
return answers.source === "guide" && answers.packageJsonExists;
}
},
{
type: "confirm",
name: "airbnbReact",
message: "Do you use React?",
default: false,
when(answers) {
return answers.styleguide === "airbnb";
}
},
{
type: "input",
name: "patterns",
@ -470,10 +532,7 @@ function promptUser() {
name: "format",
message: "What format do you want your config file to be in?",
default: "JavaScript",
choices: ["JavaScript", "YAML", "JSON"],
when(answers) {
return ((answers.source === "guide" && answers.packageJsonExists) || answers.source === "auto");
}
choices: ["JavaScript", "YAML", "JSON"]
},
{
type: "confirm",
@ -492,6 +551,15 @@ function promptUser() {
}
]).then(earlyAnswers => {
// early exit if no style guide is necessary
if (earlyAnswers.purpose !== "style") {
const config = processAnswers(earlyAnswers);
const modules = getModulesList(config);
return askInstallModules(modules, earlyAnswers.packageJsonExists)
.then(() => writeFile(config, earlyAnswers.format));
}
// early exit if you are using a style guide
if (earlyAnswers.source === "guide") {
if (!earlyAnswers.packageJsonExists) {
@ -501,130 +569,69 @@ function promptUser() {
if (earlyAnswers.installESLint === false && !semver.satisfies(earlyAnswers.localESLintVersion, earlyAnswers.requiredESLintVersionRange)) {
log.info(`Note: it might not work since ESLint's version is mismatched with the ${earlyAnswers.styleguide} config.`);
}
if (earlyAnswers.styleguide === "airbnb" && !earlyAnswers.airbnbReact) {
if (earlyAnswers.styleguide === "airbnb" && earlyAnswers.framework !== "react") {
earlyAnswers.styleguide = "airbnb-base";
}
const config = getConfigForStyleGuide(earlyAnswers.styleguide);
const config = ConfigOps.merge(processAnswers(earlyAnswers), getConfigForStyleGuide(earlyAnswers.styleguide));
const modules = getModulesList(config);
return askInstallModules(modules, earlyAnswers.packageJsonExists)
.then(() => writeFile(config, earlyAnswers.format));
}
// continue with the questions otherwise...
if (earlyAnswers.source === "auto") {
const combinedAnswers = Object.assign({}, earlyAnswers);
const config = processAnswers(combinedAnswers);
const modules = getModulesList(config);
return askInstallModules(modules).then(() => writeFile(config, earlyAnswers.format));
}
// continue with the style questions otherwise...
return inquirer.prompt([
{
type: "list",
name: "ecmaVersion",
message: "Which version of ECMAScript do you use?",
choices: [
{ name: "ES3", value: 3 },
{ name: "ES5", value: 5 },
{ name: "ES2015", value: 2015 },
{ name: "ES2016", value: 2016 },
{ name: "ES2017", value: 2017 },
{ name: "ES2018", value: 2018 }
],
default: 1 // This is the index in the choices list
name: "indent",
message: "What style of indentation do you use?",
default: "tab",
choices: [{ name: "Tabs", value: "tab" }, { name: "Spaces", value: 4 }]
},
{
type: "list",
name: "quotes",
message: "What quotes do you use for strings?",
default: "double",
choices: [{ name: "Double", value: "double" }, { name: "Single", value: "single" }]
},
{
type: "list",
name: "linebreak",
message: "What line endings do you use?",
default: "unix",
choices: [{ name: "Unix", value: "unix" }, { name: "Windows", value: "windows" }]
},
{
type: "confirm",
name: "modules",
message: "Are you using ES6 modules?",
default: false,
when(answers) {
return answers.ecmaVersion >= 2015;
}
name: "semi",
message: "Do you require semicolons?",
default: true
},
{
type: "checkbox",
name: "env",
message: "Where will your code run?",
default: ["browser"],
choices: [{ name: "Browser", value: "browser" }, { name: "Node", value: "node" }]
},
{
type: "confirm",
name: "commonjs",
message: "Do you use CommonJS?",
default: false,
when(answers) {
return answers.env.some(env => env === "browser");
}
},
{
type: "confirm",
name: "jsx",
message: "Do you use JSX?",
default: false
},
{
type: "confirm",
name: "react",
message: "Do you use React?",
default: false,
when(answers) {
return answers.jsx;
}
type: "list",
name: "format",
message: "What format do you want your config file to be in?",
default: "JavaScript",
choices: ["JavaScript", "YAML", "JSON"]
}
]).then(secondAnswers => {
]).then(answers => {
const totalAnswers = Object.assign({}, earlyAnswers, answers);
// early exit if you are using automatic style generation
if (earlyAnswers.source === "auto") {
const combinedAnswers = Object.assign({}, earlyAnswers, secondAnswers);
const config = processAnswers(totalAnswers);
const modules = getModulesList(config);
const config = processAnswers(combinedAnswers);
const modules = getModulesList(config);
return askInstallModules(modules).then(() => writeFile(config, earlyAnswers.format));
}
// continue with the style questions otherwise...
return inquirer.prompt([
{
type: "list",
name: "indent",
message: "What style of indentation do you use?",
default: "tab",
choices: [{ name: "Tabs", value: "tab" }, { name: "Spaces", value: 4 }]
},
{
type: "list",
name: "quotes",
message: "What quotes do you use for strings?",
default: "double",
choices: [{ name: "Double", value: "double" }, { name: "Single", value: "single" }]
},
{
type: "list",
name: "linebreak",
message: "What line endings do you use?",
default: "unix",
choices: [{ name: "Unix", value: "unix" }, { name: "Windows", value: "windows" }]
},
{
type: "confirm",
name: "semi",
message: "Do you require semicolons?",
default: true
},
{
type: "list",
name: "format",
message: "What format do you want your config file to be in?",
default: "JavaScript",
choices: ["JavaScript", "YAML", "JSON"]
}
]).then(answers => {
const totalAnswers = Object.assign({}, earlyAnswers, secondAnswers, answers);
const config = processAnswers(totalAnswers);
const modules = getModulesList(config);
return askInstallModules(modules).then(() => writeFile(config, answers.format));
});
return askInstallModules(modules).then(() => writeFile(config, answers.format));
});
});
}

View File

@ -386,12 +386,14 @@ module.exports = {
case true:
case "true":
case "writeable":
case "writable":
return "writeable";
case null:
case false:
case "false":
case "readable":
case "readonly":
return "readable";
// Fallback to minimize compatibility impact

View File

@ -85,10 +85,12 @@ module.exports = {
type: "object",
properties: {
getWithoutSet: {
type: "boolean"
type: "boolean",
default: false
},
setWithoutGet: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -34,11 +34,13 @@ module.exports = {
type: "object",
properties: {
multiline: {
type: "boolean"
type: "boolean",
default: true
},
minItems: {
type: ["integer", "null"],
minimum: 0
minimum: 0,
default: null
}
},
additionalProperties: false

View File

@ -155,7 +155,8 @@ module.exports = {
type: "object",
properties: {
allowImplicit: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -34,11 +34,13 @@ module.exports = {
type: "object",
properties: {
multiline: {
type: "boolean"
type: "boolean",
default: false
},
minItems: {
type: ["integer", "null"],
minimum: 0
minimum: 0,
default: null
}
},
additionalProperties: false

View File

@ -46,7 +46,7 @@ module.exports = {
{
type: "object",
properties: {
requireReturnForObjectLiteral: { type: "boolean" }
requireReturnForObjectLiteral: { type: "boolean", default: false }
},
additionalProperties: false
}

View File

@ -35,7 +35,8 @@ module.exports = {
type: "object",
properties: {
requireForBlockBody: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -32,10 +32,12 @@ module.exports = {
type: "object",
properties: {
before: {
type: "boolean"
type: "boolean",
default: true
},
after: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -54,11 +56,10 @@ module.exports = {
create(context) {
// merge rules with default
const rule = { before: true, after: true },
option = context.options[0] || {};
const rule = Object.assign({}, context.options[0]);
rule.before = option.before !== false;
rule.after = option.after !== false;
rule.before = rule.before !== false;
rule.after = rule.after !== false;
const sourceCode = context.getSourceCode();

View File

@ -30,7 +30,8 @@ module.exports = {
type: "object",
properties: {
allowSingleLine: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -25,7 +25,8 @@ module.exports = {
type: "object",
properties: {
ignoreDestructuring: {
type: "boolean"
type: "boolean",
default: false
},
properties: {
enum: ["always", "never"]
@ -54,7 +55,7 @@ module.exports = {
const options = context.options[0] || {};
let properties = options.properties || "";
const ignoreDestructuring = options.ignoreDestructuring || false;
const ignoreDestructuring = options.ignoreDestructuring;
const allow = options.allow || [];
if (properties !== "always" && properties !== "never") {

View File

@ -17,12 +17,7 @@ const astUtils = require("../util/ast-utils");
const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
WHITESPACE = /\s/g,
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/, // TODO: Combine w/ max-len pattern?
DEFAULTS = {
ignorePattern: null,
ignoreInlineComments: false,
ignoreConsecutiveComments: false
};
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/; // TODO: Combine w/ max-len pattern?
/*
* Base schema body for defining the basic capitalization rule, ignorePattern,
@ -33,17 +28,27 @@ const SCHEMA_BODY = {
type: "object",
properties: {
ignorePattern: {
type: "string"
type: "string",
default: ""
},
ignoreInlineComments: {
type: "boolean"
type: "boolean",
default: false
},
ignoreConsecutiveComments: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
};
const DEFAULTS = Object.keys(SCHEMA_BODY.properties).reduce(
(obj, current) => {
obj[current] = SCHEMA_BODY.properties[current].default;
return obj;
},
{}
);
/**
* Get normalized options for either block or line comments from the given
@ -59,11 +64,7 @@ const SCHEMA_BODY = {
* @param {string} which Either "line" or "block".
* @returns {Object} The normalized options.
*/
function getNormalizedOptions(rawOptions, which) {
if (!rawOptions) {
return Object.assign({}, DEFAULTS);
}
function getNormalizedOptions(rawOptions = {}, which) {
return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
}

View File

@ -38,7 +38,7 @@ module.exports = {
}
},
create(context) {
const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
const config = Object.assign({}, context.options[0]);
const exceptMethods = new Set(config.exceptMethods || []);
const stack = [];

View File

@ -28,10 +28,12 @@ module.exports = {
type: "object",
properties: {
before: {
type: "boolean"
type: "boolean",
default: false
},
after: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -50,8 +52,8 @@ module.exports = {
const tokensAndComments = sourceCode.tokensAndComments;
const options = {
before: context.options[0] ? !!context.options[0].before : false,
after: context.options[0] ? !!context.options[0].after : true
before: context.options[0] ? context.options[0].before : false,
after: context.options[0] ? context.options[0].after : true
};
//--------------------------------------------------------------------------
@ -118,6 +120,10 @@ module.exports = {
report(reportItem, "before", tokens.left);
}
if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
return;
}
if (tokens.right && !options.after && tokens.right.type === "Line") {
return;
}

View File

@ -41,11 +41,13 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0
minimum: 0,
default: 20
},
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 20
}
},
additionalProperties: false
@ -63,13 +65,9 @@ module.exports = {
const option = context.options[0];
let THRESHOLD = 20;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
THRESHOLD = option.maximum;
}
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
THRESHOLD = option.max;
}
if (typeof option === "number") {
if (typeof option === "object") {
THRESHOLD = option.maximum || option.max;
} else if (typeof option === "number") {
THRESHOLD = option;
}

View File

@ -66,7 +66,8 @@ module.exports = {
type: "object",
properties: {
treatUndefinedAsUnspecified: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -33,10 +33,12 @@ module.exports = {
type: "object",
properties: {
allowKeywords: {
type: "boolean"
type: "boolean",
default: true
},
allowPattern: {
type: "string"
type: "string",
default: ""
}
},
additionalProperties: false
@ -53,7 +55,7 @@ module.exports = {
create(context) {
const options = context.options[0] || {};
const allowKeywords = options.allowKeywords === void 0 || !!options.allowKeywords;
const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
const sourceCode = context.getSourceCode();
let allowPattern;

View File

@ -38,7 +38,8 @@ module.exports = {
type: "object",
properties: {
null: {
enum: ["always", "never", "ignore"]
enum: ["always", "never", "ignore"],
default: "always"
}
},
additionalProperties: false

View File

@ -50,7 +50,8 @@ module.exports = {
type: "object",
properties: {
allowNewlines: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -27,7 +27,8 @@ module.exports = {
type: "object",
properties: {
allowArrowFunctions: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -43,7 +44,7 @@ module.exports = {
create(context) {
const style = context.options[0],
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions === true,
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions,
enforceDeclarations = (style === "declaration"),
stack = [];

View File

@ -60,7 +60,8 @@ module.exports = {
type: "object",
properties: {
allowImplicit: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -26,10 +26,11 @@ module.exports = {
type: "object",
properties: {
min: {
type: "number"
type: "integer",
default: 2
},
max: {
type: "number"
type: "integer"
},
exceptions: {
type: "array",

View File

@ -28,13 +28,16 @@ module.exports = {
type: "object",
properties: {
properties: {
type: "boolean"
type: "boolean",
default: false
},
onlyDeclarations: {
type: "boolean"
type: "boolean",
default: false
},
ignoreDestructuring: {
type: "boolean"
type: "boolean",
default: false
}
}
}

View File

@ -518,7 +518,8 @@ module.exports = {
properties: {
SwitchCase: {
type: "integer",
minimum: 0
minimum: 0,
default: 0
},
VariableDeclarator: {
oneOf: [
@ -582,7 +583,8 @@ module.exports = {
ObjectExpression: ELEMENT_LIST_SCHEMA,
ImportDeclaration: ELEMENT_LIST_SCHEMA,
flatTernaryExpressions: {
type: "boolean"
type: "boolean",
default: false
},
ignoredNodes: {
type: "array",
@ -594,7 +596,8 @@ module.exports = {
}
},
ignoreComments: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -650,7 +653,7 @@ module.exports = {
}
if (context.options[1]) {
lodash.merge(options, context.options[1]);
Object.assign(options, context.options[1]);
if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") {
options.VariableDeclarator = {

View File

@ -75,7 +75,8 @@ module.exports = {
type: "object",
properties: {
ignoreForLoopInit: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -148,16 +148,20 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
on: {
enum: ["colon", "value"]
enum: ["colon", "value"],
default: "colon"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -165,13 +169,16 @@ module.exports = {
]
},
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -183,13 +190,16 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -206,16 +216,20 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
on: {
enum: ["colon", "value"]
enum: ["colon", "value"],
default: "colon"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -223,13 +237,16 @@ module.exports = {
]
},
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -244,13 +261,16 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -259,13 +279,16 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -274,16 +297,20 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
enum: ["strict", "minimum"],
default: "strict"
},
on: {
enum: ["colon", "value"]
enum: ["colon", "value"],
default: "colon"
},
beforeColon: {
type: "boolean"
type: "boolean",
default: false
},
afterColon: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -80,16 +80,16 @@ module.exports = {
{
type: "object",
properties: {
before: { type: "boolean" },
after: { type: "boolean" },
before: { type: "boolean", default: true },
after: { type: "boolean", default: true },
overrides: {
type: "object",
properties: KEYS.reduce((retv, key) => {
retv[key] = {
type: "object",
properties: {
before: { type: "boolean" },
after: { type: "boolean" }
before: { type: "boolean", default: true },
after: { type: "boolean", default: true }
},
additionalProperties: false
};
@ -228,9 +228,9 @@ module.exports = {
* Keys are keywords (there are for every keyword).
* Values are instances of `{"before": function, "after": function}`.
*/
function parseOptions(options) {
const before = !options || options.before !== false;
const after = !options || options.after !== false;
function parseOptions(options = {}) {
const before = options.before !== false;
const after = options.after !== false;
const defaultValue = {
before: before ? expectSpaceBefore : unexpectSpaceBefore,
after: after ? expectSpaceAfter : unexpectSpaceAfter

View File

@ -31,16 +31,19 @@ module.exports = {
type: "object",
properties: {
position: {
enum: ["above", "beside"]
enum: ["above", "beside"],
default: "above"
},
ignorePattern: {
type: "string"
},
applyDefaultPatterns: {
type: "boolean"
type: "boolean",
default: true
},
applyDefaultIgnorePatterns: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -69,9 +72,9 @@ module.exports = {
ignorePattern = options.ignorePattern;
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
} else {
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
applyDefaultIgnorePatterns = options.applyDefaultPatterns;
}
}

View File

@ -68,22 +68,28 @@ module.exports = {
type: "object",
properties: {
beforeBlockComment: {
type: "boolean"
type: "boolean",
default: true
},
afterBlockComment: {
type: "boolean"
type: "boolean",
default: false
},
beforeLineComment: {
type: "boolean"
type: "boolean",
default: false
},
afterLineComment: {
type: "boolean"
type: "boolean",
default: false
},
allowBlockStart: {
type: "boolean"
type: "boolean",
default: false
},
allowBlockEnd: {
type: "boolean"
type: "boolean",
default: false
},
allowClassStart: {
type: "boolean"
@ -121,19 +127,13 @@ module.exports = {
create(context) {
const options = context.options[0] ? Object.assign({}, context.options[0]) : {};
const options = Object.assign({}, context.options[0]);
const ignorePattern = options.ignorePattern;
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
const customIgnoreRegExp = new RegExp(ignorePattern);
const applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
options.beforeLineComment = options.beforeLineComment || false;
options.afterLineComment = options.afterLineComment || false;
options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true;
options.afterBlockComment = options.afterBlockComment || false;
options.allowBlockStart = options.allowBlockStart || false;
options.allowBlockEnd = options.allowBlockEnd || false;
const sourceCode = context.getSourceCode();

View File

@ -31,7 +31,8 @@ module.exports = {
type: "object",
properties: {
exceptAfterSingleLine: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -32,11 +32,13 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0
minimum: 0,
default: 4
},
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 4
}
},
additionalProperties: false
@ -59,11 +61,8 @@ module.exports = {
option = context.options[0];
let maxDepth = 4;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
maxDepth = option.maximum;
}
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
maxDepth = option.max;
if (typeof option === "object") {
maxDepth = option.maximum || option.max;
}
if (typeof option === "number") {
maxDepth = option;

View File

@ -14,7 +14,8 @@ const OPTIONS_SCHEMA = {
properties: {
code: {
type: "integer",
minimum: 0
minimum: 0,
default: 80
},
comments: {
type: "integer",
@ -22,28 +23,35 @@ const OPTIONS_SCHEMA = {
},
tabWidth: {
type: "integer",
minimum: 0
minimum: 0,
default: 4
},
ignorePattern: {
type: "string"
},
ignoreComments: {
type: "boolean"
type: "boolean",
default: false
},
ignoreStrings: {
type: "boolean"
type: "boolean",
default: false
},
ignoreUrls: {
type: "boolean"
type: "boolean",
default: false
},
ignoreTemplateLiterals: {
type: "boolean"
type: "boolean",
default: false
},
ignoreRegExpLiterals: {
type: "boolean"
type: "boolean",
default: false
},
ignoreTrailingComments: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -121,8 +129,7 @@ module.exports = {
}
// The options object must be the last option specified…
const lastOption = context.options[context.options.length - 1];
const options = typeof lastOption === "object" ? Object.create(lastOption) : {};
const options = Object.assign({}, context.options[context.options.length - 1]);
// …but max code length…
if (typeof context.options[0] === "number") {

View File

@ -19,16 +19,20 @@ const OPTIONS_SCHEMA = {
properties: {
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 50
},
skipComments: {
type: "boolean"
type: "boolean",
default: false
},
skipBlankLines: {
type: "boolean"
type: "boolean",
default: false
},
IIFEs: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -97,18 +101,10 @@ module.exports = {
let IIFEs = false;
if (typeof option === "object") {
if (typeof option.max === "number") {
maxLines = option.max;
}
if (typeof option.skipComments === "boolean") {
skipComments = option.skipComments;
}
if (typeof option.skipBlankLines === "boolean") {
skipBlankLines = option.skipBlankLines;
}
if (typeof option.IIFEs === "boolean") {
IIFEs = option.IIFEs;
}
maxLines = option.max;
skipComments = option.skipComments;
skipBlankLines = option.skipBlankLines;
IIFEs = option.IIFEs;
} else if (typeof option === "number") {
maxLines = option;
}

View File

@ -38,13 +38,16 @@ module.exports = {
properties: {
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 300
},
skipComments: {
type: "boolean"
type: "boolean",
default: false
},
skipBlankLines: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -61,11 +64,9 @@ module.exports = {
const option = context.options[0];
let max = 300;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
if (typeof option === "object") {
max = option.max;
}
if (typeof option === "number") {
} else if (typeof option === "number") {
max = option;
}
@ -86,7 +87,7 @@ module.exports = {
/**
* Returns the line numbers of a comment that don't have any code on the same line
* @param {Node} comment The comment node to check
* @returns {int[]} The line numbers
* @returns {number[]} The line numbers
*/
function getLinesWithoutCode(comment) {
let start = comment.loc.start.line;

View File

@ -32,11 +32,13 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0
minimum: 0,
default: 10
},
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 10
}
},
additionalProperties: false
@ -57,13 +59,9 @@ module.exports = {
const option = context.options[0];
let THRESHOLD = 10;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
THRESHOLD = option.maximum;
}
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
THRESHOLD = option.max;
}
if (typeof option === "number") {
if (typeof option === "object") {
THRESHOLD = option.maximum || option.max;
} else if (typeof option === "number") {
THRESHOLD = option;
}

View File

@ -40,11 +40,13 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0
minimum: 0,
default: 3
},
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 3
}
},
additionalProperties: false
@ -62,11 +64,8 @@ module.exports = {
const option = context.options[0];
let numParams = 3;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
numParams = option.maximum;
}
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
numParams = option.max;
if (typeof option === "object") {
numParams = option.maximum || option.max;
}
if (typeof option === "number") {
numParams = option;

View File

@ -31,7 +31,8 @@ module.exports = {
properties: {
max: {
type: "integer",
minimum: 1
minimum: 1,
default: 1
}
},
additionalProperties: false

View File

@ -40,11 +40,13 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0
minimum: 0,
default: 10
},
max: {
type: "integer",
minimum: 0
minimum: 0,
default: 10
}
},
additionalProperties: false
@ -78,13 +80,9 @@ module.exports = {
topLevelFunctions = [];
let maxStatements = 10;
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
maxStatements = option.maximum;
}
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
maxStatements = option.max;
}
if (typeof option === "number") {
if (typeof option === "object") {
maxStatements = option.maximum || option.max;
} else if (typeof option === "number") {
maxStatements = option;
}

View File

@ -88,10 +88,12 @@ module.exports = {
type: "object",
properties: {
newIsCap: {
type: "boolean"
type: "boolean",
default: true
},
capIsNew: {
type: "boolean"
type: "boolean",
default: true
},
newIsCapExceptions: {
type: "array",
@ -112,7 +114,8 @@ module.exports = {
type: "string"
},
properties: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -126,7 +129,7 @@ module.exports = {
create(context) {
const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
const config = Object.assign({}, context.options[0]);
config.newIsCap = config.newIsCap !== false;
config.capIsNew = config.capIsNew !== false;

View File

@ -31,7 +31,8 @@ module.exports = {
ignoreChainWithDepth: {
type: "integer",
minimum: 1,
maximum: 10
maximum: 10,
default: 2
}
},
additionalProperties: false

View File

@ -43,7 +43,8 @@ module.exports = {
uniqueItems: true
},
int32Hint: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -41,7 +41,7 @@ module.exports = {
schema: [{
type: "object",
properties: {
allowParens: { type: "boolean" }
allowParens: { type: "boolean", default: false }
},
additionalProperties: false
}],

View File

@ -32,7 +32,8 @@ module.exports = {
type: "object",
properties: {
checkLoops: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -113,7 +113,8 @@ module.exports = {
type: "object",
properties: {
includeExports: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -31,7 +31,8 @@ module.exports = {
type: "object",
properties: {
allowElseIf: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -30,7 +30,8 @@ module.exports = {
type: "object",
properties: {
allowEmptyCatch: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -89,7 +89,7 @@ module.exports = {
{
type: "object",
properties: {
allowIndirect: { type: "boolean" }
allowIndirect: { type: "boolean", default: false }
},
additionalProperties: false
}

View File

@ -44,11 +44,11 @@ module.exports = {
{
type: "object",
properties: {
conditionalAssign: { type: "boolean" },
nestedBinaryExpressions: { type: "boolean" },
returnAssign: { type: "boolean" },
conditionalAssign: { type: "boolean", default: true },
nestedBinaryExpressions: { type: "boolean", default: true },
returnAssign: { type: "boolean", default: true },
ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
enforceForArrowConditionals: { type: "boolean" }
enforceForArrowConditionals: { type: "boolean", default: true }
},
additionalProperties: false
}

View File

@ -69,7 +69,8 @@ module.exports = {
type: "object",
properties: {
commentPattern: {
type: "string"
type: "string",
default: ""
}
},
additionalProperties: false

View File

@ -21,9 +21,9 @@ const ALLOWABLE_OPERATORS = ["~", "!!", "+", "*"];
*/
function parseOptions(options) {
return {
boolean: "boolean" in options ? Boolean(options.boolean) : true,
number: "number" in options ? Boolean(options.number) : true,
string: "string" in options ? Boolean(options.string) : true,
boolean: "boolean" in options ? options.boolean : true,
number: "number" in options ? options.number : true,
string: "string" in options ? options.string : true,
allow: options.allow || []
};
}
@ -167,13 +167,16 @@ module.exports = {
type: "object",
properties: {
boolean: {
type: "boolean"
type: "boolean",
default: true
},
number: {
type: "boolean"
type: "boolean",
default: true
},
string: {
type: "boolean"
type: "boolean",
default: true
},
allow: {
type: "array",

View File

@ -41,16 +41,20 @@ module.exports = {
type: "object",
properties: {
skipComments: {
type: "boolean"
type: "boolean",
default: false
},
skipStrings: {
type: "boolean"
type: "boolean",
default: true
},
skipTemplates: {
type: "boolean"
type: "boolean",
default: false
},
skipRegExps: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -30,10 +30,12 @@ module.exports = {
type: "object",
properties: {
allowLoop: {
type: "boolean"
type: "boolean",
default: false
},
allowSwitch: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -43,8 +45,8 @@ module.exports = {
create(context) {
const options = context.options[0];
const allowLoop = Boolean(options && options.allowLoop);
const allowSwitch = Boolean(options && options.allowSwitch);
const allowLoop = options && options.allowLoop;
const allowSwitch = options && options.allowSwitch;
let scopeInfo = null;
/**

View File

@ -24,10 +24,12 @@ module.exports = {
type: "object",
properties: {
detectObjects: {
type: "boolean"
type: "boolean",
default: false
},
enforceConst: {
type: "boolean"
type: "boolean",
default: false
},
ignore: {
type: "array",
@ -37,7 +39,8 @@ module.exports = {
uniqueItems: true
},
ignoreArrayIndexes: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -42,10 +42,10 @@ const TARGET_NODE_TYPE = /^(?:Binary|Logical)Expression$/;
* @param {Object|undefined} options - A options object to normalize.
* @returns {Object} Normalized option object.
*/
function normalizeOptions(options) {
const hasGroups = (options && options.groups && options.groups.length > 0);
function normalizeOptions(options = {}) {
const hasGroups = options.groups && options.groups.length > 0;
const groups = hasGroups ? options.groups : DEFAULT_GROUPS;
const allowSamePrecedence = (options && options.allowSamePrecedence) !== false;
const allowSamePrecedence = options.allowSamePrecedence !== false;
return {
groups,
@ -95,7 +95,8 @@ module.exports = {
uniqueItems: true
},
allowSamePrecedence: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -30,10 +30,12 @@ module.exports = {
type: "object",
properties: {
grouping: {
type: "boolean"
type: "boolean",
default: false
},
allowCall: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -38,7 +38,8 @@ module.exports = {
additionalProperties: false
},
ignoreEOLComments: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -55,7 +55,7 @@ module.exports = {
},
create(context) {
const props = context.options[0] && Boolean(context.options[0].props);
const props = context.options[0] && context.options[0].props;
const ignoredPropertyAssignmentsFor = context.options[0] && context.options[0].ignorePropertyModificationsFor || [];
/**

View File

@ -26,7 +26,8 @@ module.exports = {
type: "object",
properties: {
allowForLoopAfterthoughts: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -24,7 +24,7 @@ module.exports = {
{
type: "object",
properties: {
builtinGlobals: { type: "boolean" }
builtinGlobals: { type: "boolean", default: false }
},
additionalProperties: false
}
@ -33,7 +33,7 @@ module.exports = {
create(context) {
const options = {
builtinGlobals: Boolean(context.options[0] && context.options[0].builtinGlobals)
builtinGlobals: context.options[0] && context.options[0].builtinGlobals
};
/**

View File

@ -179,7 +179,8 @@ module.exports = {
type: "object",
properties: {
props: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -4,6 +4,19 @@
*/
"use strict";
/**
* Determines if a variable safely shadows undefined.
* This is the case when a variable named `undefined` is never assigned to a value (i.e. it always shares the same value
* as the global).
* @param {eslintScope.Variable} variable The variable to check
* @returns {boolean} true if this variable safely shadows `undefined`
*/
function safelyShadowsUndefined(variable) {
return variable.name === "undefined" &&
variable.references.every(ref => !ref.isWrite()) &&
variable.defs.every(def => def.node.type === "VariableDeclarator" && def.node.init === null);
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@ -24,12 +37,13 @@ module.exports = {
create(context) {
const RESTRICTED = ["undefined", "NaN", "Infinity", "arguments", "eval"];
const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]);
return {
"VariableDeclaration, :function, CatchClause"(node) {
for (const variable of context.getDeclaredVariables(node)) {
if (variable.defs.length > 0 && RESTRICTED.includes(variable.name)) {
if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) {
context.report({
node: variable.defs[0].name,
message: "Shadowing of global property '{{idName}}'.",

View File

@ -30,8 +30,8 @@ module.exports = {
{
type: "object",
properties: {
builtinGlobals: { type: "boolean" },
hoist: { enum: ["all", "functions", "never"] },
builtinGlobals: { type: "boolean", default: false },
hoist: { enum: ["all", "functions", "never"], default: "functions" },
allow: {
type: "array",
items: {
@ -47,7 +47,7 @@ module.exports = {
create(context) {
const options = {
builtinGlobals: Boolean(context.options[0] && context.options[0].builtinGlobals),
builtinGlobals: context.options[0] && context.options[0].builtinGlobals,
hoist: (context.options[0] && context.options[0].hoist) || "functions",
allow: (context.options[0] && context.options[0].allow) || []
};

View File

@ -27,7 +27,8 @@ module.exports = {
type: "object",
properties: {
allowAtRootLevel: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -30,7 +30,8 @@ module.exports = {
type: "object",
properties: {
allowIndentationTabs: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -32,10 +32,12 @@ module.exports = {
type: "object",
properties: {
skipBlankLines: {
type: "boolean"
type: "boolean",
default: false
},
ignoreComments: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -52,7 +54,7 @@ module.exports = {
const options = context.options[0] || {},
skipBlankLines = options.skipBlankLines || false,
ignoreComments = typeof options.ignoreComments === "boolean" && options.ignoreComments;
ignoreComments = options.ignoreComments || false;
/**
* Report the error message

View File

@ -39,7 +39,8 @@ module.exports = {
type: "object",
properties: {
typeof: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -31,13 +31,16 @@ module.exports = {
}
},
allowAfterThis: {
type: "boolean"
type: "boolean",
default: false
},
allowAfterSuper: {
type: "boolean"
type: "boolean",
default: false
},
enforceInMethodNames: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -38,7 +38,8 @@ module.exports = {
type: "object",
properties: {
defaultAssignment: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -24,13 +24,16 @@ module.exports = {
type: "object",
properties: {
allowShortCircuit: {
type: "boolean"
type: "boolean",
default: false
},
allowTernary: {
type: "boolean"
type: "boolean",
default: false
},
allowTaggedTemplates: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -37,22 +37,26 @@ module.exports = {
type: "object",
properties: {
vars: {
enum: ["all", "local"]
enum: ["all", "local"],
default: "all"
},
varsIgnorePattern: {
type: "string"
},
args: {
enum: ["all", "after-used", "none"]
enum: ["all", "after-used", "none"],
default: "after-used"
},
ignoreRestSiblings: {
type: "boolean"
type: "boolean",
default: false
},
argsIgnorePattern: {
type: "string"
},
caughtErrors: {
enum: ["all", "none"]
enum: ["all", "none"],
default: "none"
},
caughtErrorsIgnorePattern: {
type: "string"

View File

@ -154,9 +154,9 @@ module.exports = {
{
type: "object",
properties: {
functions: { type: "boolean" },
classes: { type: "boolean" },
variables: { type: "boolean" }
functions: { type: "boolean", default: true },
classes: { type: "boolean", default: true },
variables: { type: "boolean", default: true }
},
additionalProperties: false
}

View File

@ -26,9 +26,9 @@ module.exports = {
{
type: "object",
properties: {
ignoreDestructuring: { type: "boolean" },
ignoreImport: { type: "boolean" },
ignoreExport: { type: "boolean" }
ignoreDestructuring: { type: "boolean", default: false },
ignoreImport: { type: "boolean", default: false },
ignoreExport: { type: "boolean", default: false }
},
additionalProperties: false
}

View File

@ -26,14 +26,16 @@ const OPTION_VALUE = {
type: "object",
properties: {
multiline: {
type: "boolean"
type: "boolean",
default: false
},
minProperties: {
type: "integer",
minimum: 0
},
consistent: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false,
@ -59,9 +61,9 @@ function normalizeOptionValue(value) {
} else if (value === "never") {
minProperties = Number.POSITIVE_INFINITY;
} else {
multiline = Boolean(value.multiline);
multiline = value.multiline;
minProperties = value.minProperties || Number.POSITIVE_INFINITY;
consistent = Boolean(value.consistent);
consistent = value.consistent;
}
} else {
consistent = true;

View File

@ -25,10 +25,12 @@ module.exports = {
type: "object",
properties: {
allowAllPropertiesOnSameLine: {
type: "boolean"
type: "boolean",
default: false
},
allowMultiplePropertiesPerLine: { // Deprecated
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -40,7 +42,7 @@ module.exports = {
create(context) {
const allowSameLine = context.options[0] && (
(Boolean(context.options[0].allowAllPropertiesOnSameLine) || Boolean(context.options[0].allowMultiplePropertiesPerLine)) // Deprecated
(context.options[0].allowAllPropertiesOnSameLine || context.options[0].allowMultiplePropertiesPerLine /* Deprecated */)
);
const errorMessage = allowSameLine
? "Object properties must go on a new line if they aren't all on the same line."

View File

@ -57,7 +57,8 @@ module.exports = {
type: "object",
properties: {
avoidQuotes: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -76,13 +77,16 @@ module.exports = {
type: "object",
properties: {
ignoreConstructors: {
type: "boolean"
type: "boolean",
default: false
},
avoidQuotes: {
type: "boolean"
type: "boolean",
default: false
},
avoidExplicitReturnArrows: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -32,16 +32,20 @@ module.exports = {
type: "object",
properties: {
separateRequires: {
type: "boolean"
type: "boolean",
default: false
},
var: {
enum: ["always", "never", "consecutive"]
enum: ["always", "never", "consecutive"],
default: "always"
},
let: {
enum: ["always", "never", "consecutive"]
enum: ["always", "never", "consecutive"],
default: "always"
},
const: {
enum: ["always", "never", "consecutive"]
enum: ["always", "never", "consecutive"],
default: "always"
}
},
additionalProperties: false
@ -76,42 +80,16 @@ module.exports = {
options.let = { uninitialized: mode, initialized: mode };
options.const = { uninitialized: mode, initialized: mode };
} else if (typeof mode === "object") { // options configuration is an object
if (Object.prototype.hasOwnProperty.call(mode, "separateRequires")) {
options.separateRequires = !!mode.separateRequires;
}
if (Object.prototype.hasOwnProperty.call(mode, "var")) {
options.var = { uninitialized: mode.var, initialized: mode.var };
}
if (Object.prototype.hasOwnProperty.call(mode, "let")) {
options.let = { uninitialized: mode.let, initialized: mode.let };
}
if (Object.prototype.hasOwnProperty.call(mode, "const")) {
options.const = { uninitialized: mode.const, initialized: mode.const };
}
options.separateRequires = mode.separateRequires;
options.var = { uninitialized: mode.var, initialized: mode.var };
options.let = { uninitialized: mode.let, initialized: mode.let };
options.const = { uninitialized: mode.const, initialized: mode.const };
if (Object.prototype.hasOwnProperty.call(mode, "uninitialized")) {
if (!options.var) {
options.var = {};
}
if (!options.let) {
options.let = {};
}
if (!options.const) {
options.const = {};
}
options.var.uninitialized = mode.uninitialized;
options.let.uninitialized = mode.uninitialized;
options.const.uninitialized = mode.uninitialized;
}
if (Object.prototype.hasOwnProperty.call(mode, "initialized")) {
if (!options.var) {
options.var = {};
}
if (!options.let) {
options.let = {};
}
if (!options.const) {
options.const = {};
}
options.var.initialized = mode.initialized;
options.let.initialized = mode.initialized;
options.const.initialized = mode.initialized;
@ -257,7 +235,9 @@ module.exports = {
if (currentOptions.uninitialized === MODE_ALWAYS && currentOptions.initialized === MODE_ALWAYS) {
if (currentScope.uninitialized || currentScope.initialized) {
return false;
if (!hasRequires) {
return false;
}
}
}
@ -268,7 +248,9 @@ module.exports = {
}
if (declarationCounts.initialized > 0) {
if (currentOptions.initialized === MODE_ALWAYS && currentScope.initialized) {
return false;
if (!hasRequires) {
return false;
}
}
}
if (currentScope.required && hasRequires) {
@ -340,7 +322,11 @@ module.exports = {
* y`
* ^ afterComma
*/
if (afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line || afterComma.type === "Line" || afterComma.type === "Block") {
if (
afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line ||
afterComma.type === "Line" ||
afterComma.type === "Block"
) {
let lastComment = afterComma;
while (lastComment.type === "Line" || lastComment.type === "Block") {
@ -349,7 +335,7 @@ module.exports = {
return fixer.replaceTextRange(
[tokenAfterDeclarator.range[0], lastComment.range[0]],
`;\n${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}\n${declaration.kind} `
`;${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}${declaration.kind} `
);
}

View File

@ -5,6 +5,12 @@
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("../util/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@ -45,32 +51,45 @@ module.exports = {
minProperties: 1
}
]
},
{
type: "object",
properties: {
allowSingleLineBlocks: {
type: "boolean"
}
}
}
]
},
create(context) {
const options = {};
const config = context.options[0] || "always";
const typeOptions = context.options[0] || "always";
const exceptOptions = context.options[1] || {};
if (typeof config === "string") {
const shouldHavePadding = config === "always";
if (typeof typeOptions === "string") {
const shouldHavePadding = typeOptions === "always";
options.blocks = shouldHavePadding;
options.switches = shouldHavePadding;
options.classes = shouldHavePadding;
} else {
if (Object.prototype.hasOwnProperty.call(config, "blocks")) {
options.blocks = config.blocks === "always";
if (Object.prototype.hasOwnProperty.call(typeOptions, "blocks")) {
options.blocks = typeOptions.blocks === "always";
}
if (Object.prototype.hasOwnProperty.call(config, "switches")) {
options.switches = config.switches === "always";
if (Object.prototype.hasOwnProperty.call(typeOptions, "switches")) {
options.switches = typeOptions.switches === "always";
}
if (Object.prototype.hasOwnProperty.call(config, "classes")) {
options.classes = config.classes === "always";
if (Object.prototype.hasOwnProperty.call(typeOptions, "classes")) {
options.classes = typeOptions.classes === "always";
}
}
if (Object.prototype.hasOwnProperty.call(exceptOptions, "allowSingleLineBlocks")) {
options.allowSingleLineBlocks = exceptOptions.allowSingleLineBlocks === true;
}
const ALWAYS_MESSAGE = "Block must be padded by blank lines.",
NEVER_MESSAGE = "Block must not be padded by blank lines.";
@ -177,6 +196,10 @@ module.exports = {
blockHasTopPadding = isPaddingBetweenTokens(tokenBeforeFirst, firstBlockToken),
blockHasBottomPadding = isPaddingBetweenTokens(lastBlockToken, tokenAfterLast);
if (options.allowSingleLineBlocks && astUtils.isTokenOnSameLine(tokenBeforeFirst, tokenAfterLast)) {
return;
}
if (requirePaddingFor(node)) {
if (!blockHasTopPadding) {
context.report({

View File

@ -146,10 +146,12 @@ module.exports = {
type: "object",
properties: {
allowNamedFunctions: {
type: "boolean"
type: "boolean",
default: false
},
allowUnboundThis: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -345,8 +345,8 @@ module.exports = {
{
type: "object",
properties: {
destructuring: { enum: ["any", "all"] },
ignoreReadBeforeAssign: { type: "boolean" }
destructuring: { enum: ["any", "all"], default: "any" },
ignoreReadBeforeAssign: { type: "boolean", default: false }
},
additionalProperties: false
}

View File

@ -19,6 +19,8 @@ module.exports = {
url: "https://eslint.org/docs/rules/prefer-destructuring"
},
fixable: "code",
schema: [
{
@ -34,10 +36,12 @@ module.exports = {
type: "object",
properties: {
array: {
type: "boolean"
type: "boolean",
default: true
},
object: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -46,10 +50,12 @@ module.exports = {
type: "object",
properties: {
array: {
type: "boolean"
type: "boolean",
default: true
},
object: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -61,10 +67,12 @@ module.exports = {
type: "object",
properties: {
array: {
type: "boolean"
type: "boolean",
default: true
},
object: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -75,7 +83,8 @@ module.exports = {
type: "object",
properties: {
enforceForRenamedProperties: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -130,10 +139,55 @@ module.exports = {
*
* @param {ASTNode} reportNode the node to report
* @param {string} type the type of destructuring that should have been done
* @param {Function|null} fix the fix function or null to pass to context.report
* @returns {void}
*/
function report(reportNode, type) {
context.report({ node: reportNode, message: "Use {{type}} destructuring.", data: { type } });
function report(reportNode, type, fix) {
context.report({
node: reportNode,
message: "Use {{type}} destructuring.",
data: { type },
fix
});
}
/**
* Determines if a node should be fixed into object destructuring
*
* The fixer only fixes the simplest case of object destructuring,
* like: `let x = a.x`;
*
* Assignment expression is not fixed.
* Array destructuring is not fixed.
* Renamed property is not fixed.
*
* @param {ASTNode} node the the node to evaluate
* @returns {boolean} whether or not the node should be fixed
*/
function shouldFix(node) {
return node.type === "VariableDeclarator" &&
node.id.type === "Identifier" &&
node.init.type === "MemberExpression" &&
node.id.name === node.init.property.name;
}
/**
* Fix a node into object destructuring.
* This function only handles the simplest case of object destructuring,
* see {@link shouldFix}.
*
* @param {SourceCodeFixer} fixer the fixer object
* @param {ASTNode} node the node to be fixed.
* @returns {Object} a fix for the node
*/
function fixIntoObjectDestructuring(fixer, node) {
const rightNode = node.init;
const sourceCode = context.getSourceCode();
return fixer.replaceText(
node,
`{${rightNode.property.name}} = ${sourceCode.getText(rightNode.object)}`
);
}
/**
@ -155,13 +209,17 @@ module.exports = {
if (isArrayIndexAccess(rightNode)) {
if (shouldCheck(reportNode.type, "array")) {
report(reportNode, "array");
report(reportNode, "array", null);
}
return;
}
const fix = shouldFix(reportNode)
? fixer => fixIntoObjectDestructuring(fixer, reportNode)
: null;
if (shouldCheck(reportNode.type, "object") && enforceForRenamedProperties) {
report(reportNode, "object");
report(reportNode, "object", fix);
return;
}
@ -172,7 +230,7 @@ module.exports = {
(property.type === "Literal" && leftNode.name === property.value) ||
(property.type === "Identifier" && leftNode.name === property.name && !rightNode.computed)
) {
report(reportNode, "object");
report(reportNode, "object", fix);
}
}
}

View File

@ -27,7 +27,7 @@ module.exports = {
{
type: "object",
properties: {
allowEmptyReject: { type: "boolean" }
allowEmptyReject: { type: "boolean", default: false }
},
additionalProperties: false
}

View File

@ -59,7 +59,7 @@ module.exports = {
},
schema: [],
fixable: "code"
fixable: null
},
create(context) {
@ -78,18 +78,7 @@ module.exports = {
if (isValidThisArg(expectedThis, thisArg, sourceCode)) {
context.report({
node,
message: "Use the spread operator instead of '.apply()'.",
fix(fixer) {
if (expectedThis && expectedThis.type !== "Identifier") {
// Don't fix cases where the `this` value could be a computed expression.
return null;
}
const propertyDot = sourceCode.getFirstTokenBetween(applied, node.callee.property, token => token.value === ".");
return fixer.replaceTextRange([propertyDot.range[0], node.range[1]], `(...${sourceCode.getText(node.arguments[1])})`);
}
message: "Use the spread operator instead of '.apply()'."
});
}
}

View File

@ -32,7 +32,8 @@ module.exports = {
type: "array",
items: [
{
enum: ["always", "as-needed", "consistent", "consistent-as-needed"]
enum: ["always", "as-needed", "consistent", "consistent-as-needed"],
default: "always"
}
],
minItems: 0,
@ -42,19 +43,23 @@ module.exports = {
type: "array",
items: [
{
enum: ["always", "as-needed", "consistent", "consistent-as-needed"]
enum: ["always", "as-needed", "consistent", "consistent-as-needed"],
default: "always"
},
{
type: "object",
properties: {
keywords: {
type: "boolean"
type: "boolean",
default: false
},
unnecessary: {
type: "boolean"
type: "boolean",
default: true
},
numbers: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -100,10 +100,12 @@ module.exports = {
type: "object",
properties: {
avoidEscape: {
type: "boolean"
type: "boolean",
default: false
},
allowTemplateLiterals: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -23,22 +23,28 @@ module.exports = {
type: "object",
properties: {
ClassDeclaration: {
type: "boolean"
type: "boolean",
default: false
},
MethodDefinition: {
type: "boolean"
type: "boolean",
default: false
},
FunctionDeclaration: {
type: "boolean"
type: "boolean",
default: true
},
ArrowFunctionExpression: {
type: "boolean"
type: "boolean",
default: false
},
FunctionExpression: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
additionalProperties: false,
default: {}
}
},
additionalProperties: false
@ -58,7 +64,7 @@ module.exports = {
ArrowFunctionExpression: false,
FunctionExpression: false
};
const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});
const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
/**
* Report the error message

View File

@ -29,10 +29,12 @@ module.exports = {
type: "object",
properties: {
before: {
type: "boolean"
type: "boolean",
default: false
},
after: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false
@ -48,12 +50,8 @@ module.exports = {
requireSpaceAfter = true;
if (typeof config === "object") {
if (Object.prototype.hasOwnProperty.call(config, "before")) {
requireSpaceBefore = config.before;
}
if (Object.prototype.hasOwnProperty.call(config, "after")) {
requireSpaceAfter = config.after;
}
requireSpaceBefore = config.before;
requireSpaceAfter = config.after;
}
/**

View File

@ -40,7 +40,8 @@ module.exports = {
type: "object",
properties: {
beforeStatementContinuationChars: {
enum: ["always", "any", "never"]
enum: ["always", "any", "never"],
default: "any"
}
},
additionalProperties: false
@ -58,7 +59,7 @@ module.exports = {
{
type: "object",
properties: {
omitLastInOneLineBlock: { type: "boolean" }
omitLastInOneLineBlock: { type: "boolean", default: false }
},
additionalProperties: false
}
@ -75,8 +76,8 @@ module.exports = {
const OPT_OUT_PATTERN = /^[-[(/+`]/; // One of [(/+-`
const options = context.options[1];
const never = context.options[0] === "never";
const exceptOneLine = Boolean(options && options.omitLastInOneLineBlock);
const beforeStatementContinuationChars = (options && options.beforeStatementContinuationChars) || "any";
const exceptOneLine = options && options.omitLastInOneLineBlock;
const beforeStatementContinuationChars = options && options.beforeStatementContinuationChars;
const sourceCode = context.getSourceCode();
//--------------------------------------------------------------------------

View File

@ -25,7 +25,8 @@ module.exports = {
type: "object",
properties: {
ignoreCase: {
type: "boolean"
type: "boolean",
default: false
},
memberSyntaxSortOrder: {
type: "array",
@ -37,10 +38,12 @@ module.exports = {
maxItems: 4
},
ignoreDeclarationSort: {
type: "boolean"
type: "boolean",
default: false
},
ignoreMemberSort: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -90,10 +90,12 @@ module.exports = {
type: "object",
properties: {
caseSensitive: {
type: "boolean"
type: "boolean",
default: true
},
natural: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false
@ -106,8 +108,8 @@ module.exports = {
// Parse options.
const order = context.options[0] || "asc";
const options = context.options[1];
const insensitive = (options && options.caseSensitive) === false;
const natual = Boolean(options && options.natural);
const insensitive = options && options.caseSensitive === false;
const natual = options && options.natural;
const isValidOrder = isValidOrders[
order + (insensitive ? "I" : "") + (natual ? "N" : "")
];
@ -127,8 +129,12 @@ module.exports = {
stack = stack.upper;
},
SpreadElement() {
stack.prevName = null;
},
Property(node) {
if (node.parent.type === "ObjectPattern" || node.parent.properties.some(n => n.type === "SpreadElement")) {
if (node.parent.type === "ObjectPattern") {
return;
}

View File

@ -25,7 +25,8 @@ module.exports = {
type: "object",
properties: {
ignoreCase: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -37,13 +37,16 @@ module.exports = {
type: "object",
properties: {
anonymous: {
enum: ["always", "never", "ignore"]
enum: ["always", "never", "ignore"],
default: "always"
},
named: {
enum: ["always", "never", "ignore"]
enum: ["always", "never", "ignore"],
default: "always"
},
asyncArrow: {
enum: ["always", "never", "ignore"]
enum: ["always", "never", "ignore"],
default: "always"
}
},
additionalProperties: false

View File

@ -26,7 +26,8 @@ module.exports = {
type: "object",
properties: {
int32Hint: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -32,10 +32,12 @@ module.exports = {
type: "object",
properties: {
words: {
type: "boolean"
type: "boolean",
default: true
},
nonwords: {
type: "boolean"
type: "boolean",
default: false
},
overrides: {
type: "object",
@ -58,7 +60,7 @@ module.exports = {
},
create(context) {
const options = context.options && Array.isArray(context.options) && context.options[0] || { words: true, nonwords: false };
const options = context.options[0] || { words: true, nonwords: false };
const sourceCode = context.getSourceCode();

View File

@ -215,7 +215,8 @@ module.exports = {
}
},
balanced: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

View File

@ -30,8 +30,8 @@ module.exports = {
{
type: "object",
properties: {
before: { type: "boolean" },
after: { type: "boolean" }
before: { type: "boolean", default: false },
after: { type: "boolean", default: true }
},
additionalProperties: false
}

View File

@ -42,22 +42,27 @@ module.exports = {
}
},
requireReturn: {
type: "boolean"
type: "boolean",
default: true
},
requireParamDescription: {
type: "boolean"
type: "boolean",
default: true
},
requireReturnDescription: {
type: "boolean"
type: "boolean",
default: true
},
matchDescription: {
type: "string"
},
requireReturnType: {
type: "boolean"
type: "boolean",
default: true
},
requireParamType: {
type: "boolean"
type: "boolean",
default: true
}
},
additionalProperties: false

View File

@ -24,7 +24,8 @@ module.exports = {
type: "object",
properties: {
requireStringLiterals: {
type: "boolean"
type: "boolean",
default: false
}
},
additionalProperties: false

Some files were not shown because too many files have changed in this diff Show More