| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 39a53a0 commit e9d5cd7
645 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,6 +129,7 @@ These folks keep the project moving and are resources for help. | |||
| 129 | 129 | * Kevin Partington ([@platinumazure](https://github.com/platinumazure)) | |
| 130 | 130 | * Vitor Balocco ([@vitorbal](https://github.com/vitorbal)) | |
| 131 | 131 | * James Henry ([@JamesHenry](https://github.com/JamesHenry)) | |
| 132 | + * Teddy Katz ([@not-an-aardvark](https://github.com/not-an-aardvark)) | ||
| 132 | 133 | ||
| 133 | 134 | ## Releases | |
| 134 | 135 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,13 +5,15 @@ | |||
| 5 | 5 | * @author Nicholas C. Zakas | |
| 6 | 6 | */ | |
| 7 | 7 | ||
| 8 | + /* eslint no-console:off, no-process-exit:off */ | ||
| 9 | + | ||
| 8 | 10 | "use strict"; | |
| 9 | 11 | ||
| 10 | 12 | //------------------------------------------------------------------------------ | |
| 11 | 13 | // Helpers | |
| 12 | 14 | //------------------------------------------------------------------------------ | |
| 13 | 15 | ||
| 14 | - var useStdIn = (process.argv.indexOf("--stdin") > -1), | ||
| 16 | + const useStdIn = (process.argv.indexOf("--stdin") > -1), | ||
| 15 | 17 | init = (process.argv.indexOf("--init") > -1), | |
| 16 | 18 | debug = (process.argv.indexOf("--debug") > -1); | |
| 17 | 19 | ||
@@ -25,7 +27,7 @@ if (debug) { | |||
| 25 | 27 | //------------------------------------------------------------------------------ | |
| 26 | 28 | ||
| 27 | 29 | // now we can safely include the other modules that use debug | |
| 28 | - var concat = require("concat-stream"), | ||
| 30 | + const concat = require("concat-stream"), | ||
| 29 | 31 | cli = require("../lib/cli"), | |
| 30 | 32 | path = require("path"), | |
| 31 | 33 | fs = require("fs"); | |
@@ -34,15 +36,16 @@ var concat = require("concat-stream"), | |||
| 34 | 36 | // Execution | |
| 35 | 37 | //------------------------------------------------------------------------------ | |
| 36 | 38 | ||
| 37 | - process.on("uncaughtException", function(err){ | ||
| 39 | + process.on("uncaughtException", function(err) { | ||
| 40 | + | ||
| 38 | 41 | // lazy load | |
| 39 | - var lodash = require("lodash"); | ||
| 42 | + const lodash = require("lodash"); | ||
| 40 | 43 | ||
| 41 | 44 | if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) { | |
| 42 | - var template = lodash.template(fs.readFileSync(path.resolve(__dirname, "../messages/" + err.messageTemplate + ".txt"), "utf-8")); | ||
| 45 | + const template = lodash.template(fs.readFileSync(path.resolve(__dirname, `../messages/${err.messageTemplate}.txt`), "utf-8")); | ||
| 43 | 46 | ||
| 44 | 47 | console.log("\nOops! Something went wrong! :("); | |
| 45 | - console.log("\n" + template(err.messageData || {})); | ||
| 48 | + console.log(`\n${template(err.messageData || {})}`); | ||
| 46 | 49 | } else { | |
| 47 | 50 | console.log(err.message); | |
| 48 | 51 | console.log(err.stack); | |
@@ -53,16 +56,11 @@ process.on("uncaughtException", function(err){ | |||
| 53 | 56 | ||
| 54 | 57 | if (useStdIn) { | |
| 55 | 58 | process.stdin.pipe(concat({ encoding: "string" }, function(text) { | |
| 56 | - try { | ||
| 57 | - process.exitCode = cli.execute(process.argv, text); | ||
| 58 | - } catch (ex) { | ||
| 59 | - console.error(ex.message); | ||
| 60 | - console.error(ex.stack); | ||
| 61 | - process.exitCode = 1; | ||
| 62 | - } | ||
| 59 | + process.exitCode = cli.execute(process.argv, text); | ||
| 63 | 60 | })); | |
| 64 | 61 | } else if (init) { | |
| 65 | - var configInit = require("../lib/config/config-initializer"); | ||
| 62 | + const configInit = require("../lib/config/config-initializer"); | ||
| 63 | + | ||
| 66 | 64 | configInit.initializeConfig(function(err) { | |
| 67 | 65 | if (err) { | |
| 68 | 66 | process.exitCode = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,6 +158,7 @@ | |||
| 158 | 158 | "eqeqeq": "off", | |
| 159 | 159 | "func-call-spacing": "off", | |
| 160 | 160 | "func-names": "off", | |
| 161 | + "func-name-matching": "off", | ||
| 161 | 162 | "func-style": "off", | |
| 162 | 163 | "generator-star-spacing": "off", | |
| 163 | 164 | "global-require": "off", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -560,6 +560,7 @@ module.exports = { | |||
| 560 | 560 | /* falls through */ | |
| 561 | 561 | ||
| 562 | 562 | case "UnaryExpression": | |
| 563 | + case "AwaitExpression": | ||
| 563 | 564 | return 14; | |
| 564 | 565 | ||
| 565 | 566 | case "UpdateExpression": | |
@@ -715,5 +716,27 @@ module.exports = { | |||
| 715 | 716 | } | |
| 716 | 717 | ||
| 717 | 718 | return directives; | |
| 719 | + }, | ||
| 720 | + | ||
| 721 | + | ||
| 722 | + /** | ||
| 723 | + * Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added | ||
| 724 | + after the node will be parsed as a decimal point, rather than a property-access dot. | ||
| 725 | + * @param {ASTNode} node - The node to check. | ||
| 726 | + * @returns {boolean} `true` if this node is a decimal integer. | ||
| 727 | + * @example | ||
| 728 | + * | ||
| 729 | + * 5 // true | ||
| 730 | + * 5. // false | ||
| 731 | + * 5.0 // false | ||
| 732 | + * 05 // false | ||
| 733 | + * 0x5 // false | ||
| 734 | + * 0b101 // false | ||
| 735 | + * 0o5 // false | ||
| 736 | + * 5e0 // false | ||
| 737 | + * '5' // false | ||
| 738 | + */ | ||
| 739 | + isDecimalInteger(node) { | ||
| 740 | + return node.type === "Literal" && typeof node.value === "number" && /^(0|[1-9]\d*)$/.test(node.raw); | ||
| 718 | 741 | } | |
| 719 | 742 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,8 @@ const debug = require("debug")("eslint:cli-engine"); | |||
| 75 | 75 | * @property {LintMessage[]} messages All of the messages for the result. | |
| 76 | 76 | * @property {number} errorCount Number or errors for the result. | |
| 77 | 77 | * @property {number} warningCount Number or warnings for the result. | |
| 78 | + * @property {string=} [source] The source code of the file that was linted. | ||
| 79 | + * @property {string=} [output] The source code of the file that was linted, with as many fixes applied as possible. | ||
| 78 | 80 | */ | |
| 79 | 81 | ||
| 80 | 82 | //------------------------------------------------------------------------------ | |
@@ -150,10 +152,10 @@ function multipassFix(text, config, options) { | |||
| 150 | 152 | do { | |
| 151 | 153 | passNumber++; | |
| 152 | 154 | ||
| 153 | - debug("Linting code for " + options.filename + " (pass " + passNumber + ")"); | ||
| 155 | + debug(`Linting code for ${options.filename} (pass ${passNumber})`); | ||
| 154 | 156 | messages = eslint.verify(text, config, options); | |
| 155 | 157 | ||
| 156 | - debug("Generating fixed text for " + options.filename + " (pass " + passNumber + ")"); | ||
| 158 | + debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`); | ||
| 157 | 159 | fixedResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages); | |
| 158 | 160 | ||
| 159 | 161 | // stop if there are any syntax errors. | |
@@ -175,7 +177,7 @@ function multipassFix(text, config, options) { | |||
| 175 | 177 | ||
| 176 | 178 | ||
| 177 | 179 | /* | |
| 178 | - * If the last result had fixes, we need to lint again to me sure we have | ||
| 180 | + * If the last result had fixes, we need to lint again to be sure we have | ||
| 179 | 181 | * the most up-to-date information. | |
| 180 | 182 | */ | |
| 181 | 183 | if (fixedResult.fixed) { | |
@@ -198,7 +200,7 @@ function multipassFix(text, config, options) { | |||
| 198 | 200 | * @param {string} filename An optional string representing the texts filename. | |
| 199 | 201 | * @param {boolean} fix Indicates if fixes should be processed. | |
| 200 | 202 | * @param {boolean} allowInlineConfig Allow/ignore comments that change config. | |
| 201 | - * @returns {Result} The results for linting on this text. | ||
| 203 | + * @returns {LintResult} The results for linting on this text. | ||
| 202 | 204 | * @private | |
| 203 | 205 | */ | |
| 204 | 206 | function processText(text, configHelper, filename, fix, allowInlineConfig) { | |
@@ -218,7 +220,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) { | |||
| 218 | 220 | } | |
| 219 | 221 | ||
| 220 | 222 | filename = filename || "<text>"; | |
| 221 | - debug("Linting " + filename); | ||
| 223 | + debug(`Linting ${filename}`); | ||
| 222 | 224 | const config = configHelper.getConfig(filePath); | |
| 223 | 225 | ||
| 224 | 226 | if (config.plugins) { | |
@@ -279,6 +281,10 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) { | |||
| 279 | 281 | result.output = fixedResult.output; | |
| 280 | 282 | } | |
| 281 | 283 | ||
| 284 | + if (result.errorCount + result.warningCount > 0 && typeof result.output === "undefined") { | ||
| 285 | + result.source = text; | ||
| 286 | + } | ||
| 287 | + | ||
| 282 | 288 | return result; | |
| 283 | 289 | } | |
| 284 | 290 | ||
@@ -288,7 +294,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) { | |||
| 288 | 294 | * @param {string} filename The filename of the file being checked. | |
| 289 | 295 | * @param {Object} configHelper The configuration options for ESLint. | |
| 290 | 296 | * @param {Object} options The CLIEngine options object. | |
| 291 | - * @returns {Result} The results for linting on this file. | ||
| 297 | + * @returns {LintResult} The results for linting on this file. | ||
| 292 | 298 | * @private | |
| 293 | 299 | */ | |
| 294 | 300 | function processFile(filename, configHelper, options) { | |
@@ -304,7 +310,7 @@ function processFile(filename, configHelper, options) { | |||
| 304 | 310 | * Returns result with warning by ignore settings | |
| 305 | 311 | * @param {string} filePath - File path of checked code | |
| 306 | 312 | * @param {string} baseDir - Absolute path of base directory | |
| 307 | - * @returns {Result} Result with single warning | ||
| 313 | + * @returns {LintResult} Result with single warning | ||
| 308 | 314 | * @private | |
| 309 | 315 | */ | |
| 310 | 316 | function createIgnoreResult(filePath, baseDir) { | |
@@ -376,7 +382,7 @@ function getCacheFile(cacheFile, cwd) { | |||
| 376 | 382 | * @returns {string} the resolved path to the cacheFile | |
| 377 | 383 | */ | |
| 378 | 384 | function getCacheFileForDirectory() { | |
| 379 | - return path.join(resolvedCacheFile, ".cache_" + hash(cwd)); | ||
| 385 | + return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`); | ||
| 380 | 386 | } | |
| 381 | 387 | ||
| 382 | 388 | let fileStats; | |
@@ -461,7 +467,7 @@ function CLIEngine(options) { | |||
| 461 | 467 | const cwd = this.options.cwd; | |
| 462 | 468 | ||
| 463 | 469 | this.options.rulePaths.forEach(function(rulesdir) { | |
| 464 | - debug("Loading rules from " + rulesdir); | ||
| 470 | + debug(`Loading rules from ${rulesdir}`); | ||
| 465 | 471 | rules.load(rulesdir, cwd); | |
| 466 | 472 | }); | |
| 467 | 473 | } | |
@@ -497,13 +503,13 @@ CLIEngine.getFormatter = function(format) { | |||
| 497 | 503 | ||
| 498 | 504 | formatterPath = path.resolve(cwd, format); | |
| 499 | 505 | } else { | |
| 500 | - formatterPath = "./formatters/" + format; | ||
| 506 | + formatterPath = `./formatters/${format}`; | ||
| 501 | 507 | } | |
| 502 | 508 | ||
| 503 | 509 | try { | |
| 504 | 510 | return require(formatterPath); | |
| 505 | 511 | } catch (ex) { | |
| 506 | - ex.message = "There was a problem loading formatter: " + formatterPath + "\nError: " + ex.message; | ||
| 512 | + ex.message = `There was a problem loading formatter: ${formatterPath}\nError: ${ex.message}`; | ||
| 507 | 513 | throw ex; | |
| 508 | 514 | } | |
| 509 | 515 | ||
@@ -524,12 +530,13 @@ CLIEngine.getErrorResults = function(results) { | |||
| 524 | 530 | const filteredMessages = result.messages.filter(isErrorMessage); | |
| 525 | 531 | ||
| 526 | 532 | if (filteredMessages.length > 0) { | |
| 527 | - filtered.push({ | ||
| 528 | - filePath: result.filePath, | ||
| 529 | - messages: filteredMessages, | ||
| 530 | - errorCount: filteredMessages.length, | ||
| 531 | - warningCount: 0 | ||
| 532 | - }); | ||
| 533 | + filtered.push( | ||
| 534 | + Object.assign(result, { | ||
| 535 | + messages: filteredMessages, | ||
| 536 | + errorCount: filteredMessages.length, | ||
| 537 | + warningCount: 0 | ||
| 538 | + }) | ||
| 539 | + ); | ||
| 533 | 540 | } | |
| 534 | 541 | }); | |
| 535 | 542 | ||
@@ -608,7 +615,7 @@ CLIEngine.prototype = { | |||
| 608 | 615 | ||
| 609 | 616 | const eslintVersion = pkg.version; | |
| 610 | 617 | ||
| 611 | - prevConfig.hash = hash(eslintVersion + "_" + stringify(config)); | ||
| 618 | + prevConfig.hash = hash(`${eslintVersion}_${stringify(config)}`); | ||
| 612 | 619 | } | |
| 613 | 620 | ||
| 614 | 621 | return prevConfig.hash; | |
@@ -645,7 +652,7 @@ CLIEngine.prototype = { | |||
| 645 | 652 | const changed = descriptor.changed || meta.hashOfConfig !== hashOfConfig; | |
| 646 | 653 | ||
| 647 | 654 | if (!changed) { | |
| 648 | - debug("Skipping file since hasn't changed: " + filename); | ||
| 655 | + debug(`Skipping file since hasn't changed: ${filename}`); | ||
| 649 | 656 | ||
| 650 | 657 | /* | |
| 651 | 658 | * Add the the cached results (always will be 0 error and | |
@@ -662,7 +669,7 @@ CLIEngine.prototype = { | |||
| 662 | 669 | fileCache.destroy(); | |
| 663 | 670 | } | |
| 664 | 671 | ||
| 665 | - debug("Processing " + filename); | ||
| 672 | + debug(`Processing ${filename}`); | ||
| 666 | 673 | ||
| 667 | 674 | const res = processFile(filename, configHelper, options); | |
| 668 | 675 | ||
@@ -674,7 +681,7 @@ CLIEngine.prototype = { | |||
| 674 | 681 | * next execution will also operate on this file | |
| 675 | 682 | */ | |
| 676 | 683 | if (res.errorCount > 0 || res.warningCount > 0) { | |
| 677 | - debug("File has problems, skipping it: " + filename); | ||
| 684 | + debug(`File has problems, skipping it: ${filename}`); | ||
| 678 | 685 | ||
| 679 | 686 | // remove the entry from the cache | |
| 680 | 687 | fileCache.removeEntry(filename); | |
@@ -713,7 +720,7 @@ CLIEngine.prototype = { | |||
| 713 | 720 | fileCache.reconcile(); | |
| 714 | 721 | } | |
| 715 | 722 | ||
| 716 | - debug("Linting complete in: " + (Date.now() - startTime) + "ms"); | ||
| 723 | + debug(`Linting complete in: ${Date.now() - startTime}ms`); | ||
| 717 | 724 | ||
| 718 | 725 | return { | |
| 719 | 726 | results, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,15 +135,30 @@ const cli = { | |||
| 135 | 135 | ||
| 136 | 136 | if (currentOptions.version) { // version from package.json | |
| 137 | 137 | ||
| 138 | - log.info("v" + require("../package.json").version); | ||
| 138 | + log.info(`v${require("../package.json").version}`); | ||
| 139 | 139 | ||
| 140 | + } else if (currentOptions.printConfig) { | ||
| 141 | + if (files.length) { | ||
| 142 | + log.error("The --print-config option must be used with exactly one file name."); | ||
| 143 | + return 1; | ||
| 144 | + } else if (text) { | ||
| 145 | + log.error("The --print-config option is not available for piped-in code."); | ||
| 146 | + return 1; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + const engine = new CLIEngine(translateOptions(currentOptions)); | ||
| 150 | + | ||
| 151 | + const fileConfig = engine.getConfigForFile(currentOptions.printConfig); | ||
| 152 | + | ||
| 153 | + log.info(JSON.stringify(fileConfig, null, " ")); | ||
| 154 | + return 0; | ||
| 140 | 155 | } else if (currentOptions.help || (!files.length && !text)) { | |
| 141 | 156 | ||
| 142 | 157 | log.info(options.generateHelp()); | |
| 143 | 158 | ||
| 144 | 159 | } else { | |
| 145 | 160 | ||
| 146 | - debug("Running on " + (text ? "text" : "files")); | ||
| 161 | + debug(`Running on ${text ? "text" : "files"}`); | ||
| 147 | 162 | ||
| 148 | 163 | // disable --fix for piped-in code until we know how to do it correctly | |
| 149 | 164 | if (text && currentOptions.fix) { | |
@@ -153,24 +168,6 @@ const cli = { | |||
| 153 | 168 | ||
| 154 | 169 | const engine = new CLIEngine(translateOptions(currentOptions)); | |
| 155 | 170 | ||
| 156 | - if (currentOptions.printConfig) { | ||
| 157 | - if (files.length !== 1) { | ||
| 158 | - log.error("The --print-config option requires a " + | ||
| 159 | - "single file as positional argument."); | ||
| 160 | - return 1; | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - if (text) { | ||
| 164 | - log.error("The --print-config option is not available for piped-in code."); | ||
| 165 | - return 1; | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - const fileConfig = engine.getConfigForFile(files[0]); | ||
| 169 | - | ||
| 170 | - log.info(JSON.stringify(fileConfig, null, " ")); | ||
| 171 | - return 0; | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | 171 | const report = text ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files); | |
| 175 | 172 | ||
| 176 | 173 | if (currentOptions.fix) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments