From 73e3976c348d56aba94048874606364b94de9b1a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 13 Oct 2020 09:14:02 +0800 Subject: [PATCH] Add `espree` parser (#9000) Co-authored-by: Chris Brody --- changelog_unreleased/javascript/pr-9000.md | 5 + cspell.json | 1 + docs/options.md | 1 + package.json | 1 + scripts/build/config.js | 3 + src/language-js/clean.js | 2 + src/language-js/comments.js | 4 +- src/language-js/index.js | 22 ++++- src/language-js/parser-espree.js | 59 ++++++++++++ src/language-js/postprocess.js | 31 ++++++- src/language-js/utils.js | 4 +- src/main/core-options.js | 1 + src/main/range-util.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 92 +++++++++++++------ tests/js/arrow-call/arrow_call.js | 5 - tests/js/arrow-call/class-property.js | 4 + tests/js/arrow-call/jsfmt.spec.js | 10 +- tests/js/arrows-bind/jsfmt.spec.js | 2 +- .../arrows/newline-before-arrow/jsfmt.spec.js | 4 +- tests/js/babel-plugins/jsfmt.spec.js | 29 +++++- tests/js/bind-expressions/jsfmt.spec.js | 4 +- tests/js/class-comment/jsfmt.spec.js | 6 +- tests/js/classes-private-fields/jsfmt.spec.js | 4 +- tests/js/classes/jsfmt.spec.js | 4 +- .../js/classes/top-level-super/jsfmt.spec.js | 2 +- .../comments-pipeline-own-line/jsfmt.spec.js | 2 +- tests/js/decorator-comments/jsfmt.spec.js | 2 +- tests/js/decorators-export/jsfmt.spec.js | 2 +- tests/js/decorators/jsfmt.spec.js | 2 +- tests/js/do/jsfmt.spec.js | 2 +- tests/js/empty-paren-comment/jsfmt.spec.js | 4 +- tests/js/export-default/escaped/jsfmt.spec.js | 4 +- tests/js/export-extension/jsfmt.spec.js | 2 +- tests/js/exports/jsfmt.spec.js | 2 +- tests/js/functional-composition/jsfmt.spec.js | 6 +- tests/js/invalid-code/jsfmt.spec.js | 2 +- tests/js/literal/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 16 +++- tests/js/logical-assignment/invalid.js | 1 + tests/js/logical-assignment/jsfmt.spec.js | 4 +- .../logical-assignment/logical-assignment.js | 1 - tests/js/module-attributes/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/js/multiparser-css/issue-5961.js | 2 +- .../no-semi-babylon-extensions/jsfmt.spec.js | 4 +- tests/js/no-semi/jsfmt.spec.js | 6 +- .../js/object-property-comment/jsfmt.spec.js | 4 +- tests/js/objects/jsfmt.spec.js | 4 +- tests/js/partial-application/jsfmt.spec.js | 2 +- tests/js/pipeline-operator/jsfmt.spec.js | 2 +- tests/js/private-in/jsfmt.spec.js | 2 +- tests/js/quote-props/jsfmt.spec.js | 6 ++ tests/js/record/jsfmt.spec.js | 2 +- tests/js/rest/jsfmt.spec.js | 5 +- tests/js/test-declarations/jsfmt.spec.js | 4 +- tests/js/throw_expressions/jsfmt.spec.js | 2 +- tests/js/top-level-await/jsfmt.spec.js | 2 +- tests/js/trailing-whitespace/jsfmt.spec.js | 4 +- tests/js/tuple/jsfmt.spec.js | 2 +- tests/js/v8_intrinsic/jsfmt.spec.js | 2 +- tests_config/run_spec.js | 34 +++++-- .../utils/compose-options-for-snapshot.js | 1 + .../utils/stringify-options-for-title.js | 2 +- .../__snapshots__/early-exit.js.snap | 7 +- .../__snapshots__/help-options.js.snap | 3 +- .../plugin-options-string.js.snap | 4 +- .../__snapshots__/plugin-options.js.snap | 7 +- .../__tests__/__snapshots__/schema.js.snap | 6 ++ .../__snapshots__/support-info.js.snap | 22 ++++- website/playground/codeSamples.js | 1 + website/playground/markdown.js | 1 + website/playground/util.js | 1 + yarn.lock | 8 +- 73 files changed, 397 insertions(+), 116 deletions(-) create mode 100644 changelog_unreleased/javascript/pr-9000.md create mode 100644 src/language-js/parser-espree.js create mode 100644 tests/js/arrow-call/class-property.js create mode 100644 tests/js/logical-assignment/invalid.js diff --git a/changelog_unreleased/javascript/pr-9000.md b/changelog_unreleased/javascript/pr-9000.md new file mode 100644 index 000000000..6f7ec68d3 --- /dev/null +++ b/changelog_unreleased/javascript/pr-9000.md @@ -0,0 +1,5 @@ +#### Add `espree` parser (#9000 by @fisker) + +A new value for the `parser` option has been added: [`espree`](https://github.com/eslint/espree) - which is the [`ESLint`](https://github.com/eslint/eslint) default parser. + +Note that `espree` only works for [ECMAScript Finished Proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md), and is stricter than the `babel` parser. diff --git a/cspell.json b/cspell.json index 72645b9a4..8e4e3f3f5 100644 --- a/cspell.json +++ b/cspell.json @@ -105,6 +105,7 @@ "esbenp", "eslintignore", "eslump", + "espree", "esproposal", "estree", "esutils", diff --git a/docs/options.md b/docs/options.md index 38d6000ad..273d33391 100644 --- a/docs/options.md +++ b/docs/options.md @@ -211,6 +211,7 @@ Valid options: - `"babel-ts"` (similar to `"typescript"` but uses Babel and its TypeScript plugin) _First available in v2.0.0_ - `"flow"` (via [flow-parser](https://github.com/facebook/flow/tree/master/src/parser)) - `"typescript"` (via [@typescript-eslint/typescript-estree](https://github.com/typescript-eslint/typescript-eslint)) _First available in v1.4.0_ +- `"espree"` (via [espree](https://github.com/eslint/espree)) _First available in v2.2.0_ - `"css"` (via [postcss](https://github.com/postcss/postcss)) _First available in v1.7.1_ - `"scss"` (via [postcss-scss](https://github.com/postcss/postcss-scss)) _First available in v1.7.1_ - `"less"` (via [postcss-less](https://github.com/shellscape/postcss-less) _First available in v1.7.1_ diff --git a/package.json b/package.json index 89c6c53f8..98e4ec3c8 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "editorconfig": "0.15.3", "editorconfig-to-prettier": "0.2.0", "escape-string-regexp": "4.0.0", + "espree": "7.3.0", "esutils": "2.0.3", "fast-glob": "3.2.4", "fast-json-stable-stringify": "2.1.0", diff --git a/scripts/build/config.js b/scripts/build/config.js index 87f46ee81..808bb71e5 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -42,6 +42,9 @@ const parsers = [ 'typeof globalThis === "object"': "true", }, }, + { + input: "src/language-js/parser-espree.js", + }, { input: "src/language-js/parser-angular.js", }, diff --git a/src/language-js/clean.js b/src/language-js/clean.js index 94f2dd47c..4f5bfbf20 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -27,6 +27,8 @@ function clean(ast, newObj, parent) { if (newObj.value) { newObj.value = newObj.value.toLowerCase(); } + } + if (ast.type === "BigIntLiteral" || ast.type === "Literal") { if (newObj.bigint) { newObj.bigint = newObj.bigint.toLowerCase(); } diff --git a/src/language-js/comments.js b/src/language-js/comments.js index 8777c4d5c..4b1629a3e 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -991,7 +991,9 @@ function getCommentChildNodes(node, options) { // } // } if ( - (options.parser === "typescript" || options.parser === "flow") && + (options.parser === "typescript" || + options.parser === "flow" || + options.parser === "espree") && node.type === "MethodDefinition" && node.value && node.value.type === "FunctionExpression" && diff --git a/src/language-js/index.js b/src/language-js/index.js index cf9a38099..7cc00f94b 100644 --- a/src/language-js/index.js +++ b/src/language-js/index.js @@ -10,7 +10,14 @@ const languages = [ require("linguist-languages/data/JavaScript.json"), (data) => ({ since: "0.0.0", - parsers: ["babel", "babel-flow", "babel-ts", "flow", "typescript"], + parsers: [ + "babel", + "espree", + "babel-flow", + "babel-ts", + "flow", + "typescript", + ], vscodeLanguageIds: ["javascript", "mongo"], extensions: [ ...data.extensions, @@ -31,7 +38,14 @@ const languages = [ })), createLanguage(require("linguist-languages/data/JSX.json"), () => ({ since: "0.0.0", - parsers: ["babel", "babel-flow", "babel-ts", "flow", "typescript"], + parsers: [ + "babel", + "babel-flow", + "babel-ts", + "flow", + "typescript", + "espree", + ], vscodeLanguageIds: ["javascriptreact"], })), createLanguage(require("linguist-languages/data/TypeScript.json"), () => ({ @@ -132,6 +146,10 @@ const parsers = { get __ng_directive() { return require("./parser-angular").parsers.__ng_directive; }, + // JS - espree + get espree() { + return require("./parser-espree").parsers.espree; + }, }; module.exports = { diff --git a/src/language-js/parser-espree.js b/src/language-js/parser-espree.js new file mode 100644 index 000000000..c65ce5be9 --- /dev/null +++ b/src/language-js/parser-espree.js @@ -0,0 +1,59 @@ +"use strict"; +const { getShebang } = require("../common/util"); +const createError = require("../common/parser-create-error"); +const { hasPragma } = require("./pragma"); +const { locStart, locEnd } = require("./loc"); +const postprocess = require("./postprocess"); + +const espreeOptions = { + range: true, + loc: true, + comment: true, + tokens: true, + sourceType: "module", + ecmaFeatures: { + jsx: true, + globalReturn: true, + impliedStrict: false, + }, +}; + +function parse(originalText, parsers, options) { + const { parse, latestEcmaVersion } = require("espree"); + espreeOptions.ecmaVersion = latestEcmaVersion; + + // Replace shebang with space + const shebang = getShebang(originalText); + const text = shebang + ? " ".repeat(shebang.length) + originalText.slice(shebang.length) + : originalText; + + let ast; + + try { + ast = parse(text, espreeOptions); + } catch (moduleError) { + try { + ast = parse(text, { ...espreeOptions, sourceType: "script" }); + } catch (scriptError) { + // throw the error for `module` parsing + + /* istanbul ignore next */ + if (typeof moduleError.lineNumber === "undefined") { + throw moduleError; + } + + throw createError(moduleError.message, { + start: { line: moduleError.lineNumber, column: moduleError.column }, + }); + } + } + + return postprocess(ast, { ...options, originalText }); +} + +module.exports = { + parsers: { + espree: { parse, astFormat: "estree", hasPragma, locStart, locEnd }, + }, +}; diff --git a/src/language-js/postprocess.js b/src/language-js/postprocess.js index a3879e3d5..ca1a55320 100644 --- a/src/language-js/postprocess.js +++ b/src/language-js/postprocess.js @@ -9,12 +9,20 @@ const { composeLoc, locStart, locEnd } = require("./loc"); const { isTypeCastComment } = require("./comments"); function postprocess(ast, options) { - if (options.parser === "typescript" || options.parser === "flow") { + if ( + options.parser === "typescript" || + options.parser === "flow" || + options.parser === "espree" + ) { includeShebang(ast, options); } // Keep Babel's non-standard ParenthesizedExpression nodes only if they have Closure-style type cast comments. - if (options.parser !== "typescript" && options.parser !== "flow") { + if ( + options.parser !== "typescript" && + options.parser !== "flow" && + options.parser !== "espree" + ) { const startOffsetsOfTypeCastedNodes = new Set(); // Comments might be attached not directly to ParenthesizedExpression but to its ancestor. @@ -48,6 +56,10 @@ function postprocess(ast, options) { ast = visitNode(ast, (node) => { switch (node.type) { + // Espree + case "ChainExpression": { + return transformChainExpression(node.expression); + } case "LogicalExpression": { // We remove unneeded parens around same-operator LogicalExpressions if (isUnbalancedLogicalTree(node)) { @@ -126,6 +138,21 @@ function postprocess(ast, options) { } } +// This is a workaround to transform `ChainExpression` from `espree` into +// `babel` shape AST, we should do the opposite, since `ChainExpression` is the +// standard `estree` AST for `optional chaining` +// https://github.com/estree/estree/blob/master/es2020.md +function transformChainExpression(node) { + if (node.type === "CallExpression") { + node.type = "OptionalCallExpression"; + node.callee = transformChainExpression(node.callee); + } else if (node.type === "MemberExpression") { + node.type = "OptionalMemberExpression"; + node.object = transformChainExpression(node.object); + } + return node; +} + function visitNode(node, fn) { let entries; diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 7ce121e44..5c2d7ae37 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -927,7 +927,7 @@ function returnArgumentHasLeadingComment(options, argument) { // // Angular does not support unquoted numbers in expressions. // -// So we play it safe and only unquote numbers for the "babel" parser. +// So we play it safe and only unquote numbers for the JavaScript parsers. // (Vue supports unquoted numbers in expressions, but let’s keep it simple.) // // Identifiers can be unquoted in more circumstances, though. @@ -945,7 +945,7 @@ function isStringPropSafeToUnquote(node, options) { )) || (isSimpleNumber(node.key.value) && String(Number(node.key.value)) === node.key.value && - options.parser === "babel")) + (options.parser === "babel" || options.parser === "espree"))) ); } diff --git a/src/main/core-options.js b/src/main/core-options.js index 1462d5185..70e8d8d40 100644 --- a/src/main/core-options.js +++ b/src/main/core-options.js @@ -129,6 +129,7 @@ const options = { { value: "babel-flow", since: "1.16.0", description: "Flow" }, { value: "babel-ts", since: "2.0.0", description: "TypeScript" }, { value: "typescript", since: "1.4.0", description: "TypeScript" }, + { value: "espree", since: "2.2.0", description: "JavaScript" }, { value: "css", since: "1.7.1", description: "CSS" }, { value: "less", since: "1.7.1", description: "Less" }, { value: "scss", since: "1.7.1", description: "SCSS" }, diff --git a/src/main/range-util.js b/src/main/range-util.js index cf041748b..c66b1fed6 100644 --- a/src/main/range-util.js +++ b/src/main/range-util.js @@ -119,6 +119,7 @@ function isSourceElement(opts, node) { case "babel-flow": case "babel-ts": case "typescript": + case "espree": return isJsSourceElement(node.type); case "json": return jsonSourceElements.has(node.type); diff --git a/tests/js/arrow-call/__snapshots__/jsfmt.spec.js.snap b/tests/js/arrow-call/__snapshots__/jsfmt.spec.js.snap index da09d5b7f..0a3a3cd0e 100644 --- a/tests/js/arrow-call/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/arrow-call/__snapshots__/jsfmt.spec.js.snap @@ -45,11 +45,6 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail"); =====================================output===================================== @@ -97,11 +92,6 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then((result) => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" @@ -156,11 +146,6 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail"); =====================================output===================================== @@ -208,11 +193,6 @@ func( veryLoooooooooooooooongName.something(), ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then((result) => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" @@ -266,11 +246,6 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail"); =====================================output===================================== @@ -318,11 +293,6 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then((result) => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" @@ -331,3 +301,65 @@ promise.then((result) => ================================================================================ `; + +exports[`class-property.js - {"arrowParens":"always"} format 1`] = ` +====================================options===================================== +arrowParens: "always" +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +=====================================output===================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +================================================================================ +`; + +exports[`class-property.js - {"trailingComma":"all"} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +trailingComma: "all" + | printWidth +=====================================input====================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +=====================================output===================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +================================================================================ +`; + +exports[`class-property.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +=====================================output===================================== +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; + +================================================================================ +`; diff --git a/tests/js/arrow-call/arrow_call.js b/tests/js/arrow-call/arrow_call.js index 536ad9e57..f4661759b 100644 --- a/tests/js/arrow-call/arrow_call.js +++ b/tests/js/arrow-call/arrow_call.js @@ -36,9 +36,4 @@ func( veryLoooooooooooooooongName.something() ); -const composition = (ViewComponent, ContainerComponent) => - class extends React.Component { - static propTypes = {}; - }; - promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail"); diff --git a/tests/js/arrow-call/class-property.js b/tests/js/arrow-call/class-property.js new file mode 100644 index 000000000..6d2b90b30 --- /dev/null +++ b/tests/js/arrow-call/class-property.js @@ -0,0 +1,4 @@ +const composition = (ViewComponent, ContainerComponent) => + class extends React.Component { + static propTypes = {}; + }; diff --git a/tests/js/arrow-call/jsfmt.spec.js b/tests/js/arrow-call/jsfmt.spec.js index 3f436996f..f7ff242dd 100644 --- a/tests/js/arrow-call/jsfmt.spec.js +++ b/tests/js/arrow-call/jsfmt.spec.js @@ -1,7 +1,15 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +const errors = { + espree: ["class-property.js"], +}; + +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors, +}); run_spec(__dirname, ["babel", "flow", "typescript"], { trailingComma: "all", + errors, }); run_spec(__dirname, ["babel", "flow", "typescript"], { arrowParens: "always", + errors, }); diff --git a/tests/js/arrows-bind/jsfmt.spec.js b/tests/js/arrows-bind/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/arrows-bind/jsfmt.spec.js +++ b/tests/js/arrows-bind/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/arrows/newline-before-arrow/jsfmt.spec.js b/tests/js/arrows/newline-before-arrow/jsfmt.spec.js index 8382eddeb..29283fa30 100644 --- a/tests/js/arrows/newline-before-arrow/jsfmt.spec.js +++ b/tests/js/arrows/newline-before-arrow/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { + errors: { espree: ["newline-before-arrow.js"] }, +}); diff --git a/tests/js/babel-plugins/jsfmt.spec.js b/tests/js/babel-plugins/jsfmt.spec.js index 0fa97049b..40fa5ab94 100644 --- a/tests/js/babel-plugins/jsfmt.spec.js +++ b/tests/js/babel-plugins/jsfmt.spec.js @@ -1,4 +1,31 @@ // Only testing babel parsing // Do not add extra parsers here -run_spec(__dirname, ["babel", "babel-ts", "babel-flow"]); +run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], { + errors: { + espree: [ + "class-properties.js", + "decimal.js", + "decorators.js", + "do-expressions.js", + "export-default-from.js", + "flow.js", + "function-bind.js", + "function-sent.js", + "module-attributes-dynamic.js", + "module-attributes-static.js", + "partial-application.js", + "pipeline-operator-fsharp.js", + "pipeline-operator-minimal.js", + "pipeline-operator-smart.js", + "private-fields-in-in.js", + "private-methods.js", + "record-tuple-record.js", + "record-tuple-tuple.js", + "throw-expressions.js", + "typescript.js", + "v8intrinsic.js", + "optional-chaining.js", + ], + }, +}); diff --git a/tests/js/bind-expressions/jsfmt.spec.js b/tests/js/bind-expressions/jsfmt.spec.js index c5f2d2b9c..18153a1a9 100644 --- a/tests/js/bind-expressions/jsfmt.spec.js +++ b/tests/js/bind-expressions/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["babel"]); -run_spec(__dirname, ["babel"], { semi: false }); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); +run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } }); diff --git a/tests/js/class-comment/jsfmt.spec.js b/tests/js/class-comment/jsfmt.spec.js index eb85eda6b..49b534281 100644 --- a/tests/js/class-comment/jsfmt.spec.js +++ b/tests/js/class-comment/jsfmt.spec.js @@ -1 +1,5 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { + espree: ["class-property.js"], + }, +}); diff --git a/tests/js/classes-private-fields/jsfmt.spec.js b/tests/js/classes-private-fields/jsfmt.spec.js index c5f2d2b9c..18153a1a9 100644 --- a/tests/js/classes-private-fields/jsfmt.spec.js +++ b/tests/js/classes-private-fields/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["babel"]); -run_spec(__dirname, ["babel"], { semi: false }); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); +run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } }); diff --git a/tests/js/classes/jsfmt.spec.js b/tests/js/classes/jsfmt.spec.js index eb85eda6b..c883bd4e5 100644 --- a/tests/js/classes/jsfmt.spec.js +++ b/tests/js/classes/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { espree: ["property.js"] }, +}); diff --git a/tests/js/classes/top-level-super/jsfmt.spec.js b/tests/js/classes/top-level-super/jsfmt.spec.js index 858ac91aa..7d3544f4b 100644 --- a/tests/js/classes/top-level-super/jsfmt.spec.js +++ b/tests/js/classes/top-level-super/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel", "typescript"]); +run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } }); diff --git a/tests/js/comments-pipeline-own-line/jsfmt.spec.js b/tests/js/comments-pipeline-own-line/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/comments-pipeline-own-line/jsfmt.spec.js +++ b/tests/js/comments-pipeline-own-line/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/decorator-comments/jsfmt.spec.js b/tests/js/decorator-comments/jsfmt.spec.js index 858ac91aa..7d3544f4b 100644 --- a/tests/js/decorator-comments/jsfmt.spec.js +++ b/tests/js/decorator-comments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel", "typescript"]); +run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } }); diff --git a/tests/js/decorators-export/jsfmt.spec.js b/tests/js/decorators-export/jsfmt.spec.js index d8894cd81..b7b6d7808 100644 --- a/tests/js/decorators-export/jsfmt.spec.js +++ b/tests/js/decorators-export/jsfmt.spec.js @@ -1,2 +1,2 @@ // TypeScript and Flow don't accept decorator after export -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/decorators/jsfmt.spec.js b/tests/js/decorators/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/decorators/jsfmt.spec.js +++ b/tests/js/decorators/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/do/jsfmt.spec.js b/tests/js/do/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/do/jsfmt.spec.js +++ b/tests/js/do/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/empty-paren-comment/jsfmt.spec.js b/tests/js/empty-paren-comment/jsfmt.spec.js index eb85eda6b..833888c25 100644 --- a/tests/js/empty-paren-comment/jsfmt.spec.js +++ b/tests/js/empty-paren-comment/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { espree: ["class-property.js"] }, +}); diff --git a/tests/js/export-default/escaped/jsfmt.spec.js b/tests/js/export-default/escaped/jsfmt.spec.js index 8382eddeb..302810e99 100644 --- a/tests/js/export-default/escaped/jsfmt.spec.js +++ b/tests/js/export-default/escaped/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { + errors: { espree: true }, +}); diff --git a/tests/js/export-extension/jsfmt.spec.js b/tests/js/export-extension/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/export-extension/jsfmt.spec.js +++ b/tests/js/export-extension/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/exports/jsfmt.spec.js b/tests/js/exports/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/exports/jsfmt.spec.js +++ b/tests/js/exports/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/functional-composition/jsfmt.spec.js b/tests/js/functional-composition/jsfmt.spec.js index eb85eda6b..ef29a17d8 100644 --- a/tests/js/functional-composition/jsfmt.spec.js +++ b/tests/js/functional-composition/jsfmt.spec.js @@ -1 +1,5 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { + espree: [], + }, +}); diff --git a/tests/js/invalid-code/jsfmt.spec.js b/tests/js/invalid-code/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/invalid-code/jsfmt.spec.js +++ b/tests/js/invalid-code/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/literal/jsfmt.spec.js b/tests/js/literal/jsfmt.spec.js index d1f25e544..23f3c3a3b 100644 --- a/tests/js/literal/jsfmt.spec.js +++ b/tests/js/literal/jsfmt.spec.js @@ -1,2 +1,2 @@ // flow-parser@0.38.0 fails to parse `1.e1`, so use babel here. -run_spec(__dirname, ["babel", "typescript"]); +run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } }); diff --git a/tests/js/logical-assignment/__snapshots__/jsfmt.spec.js.snap b/tests/js/logical-assignment/__snapshots__/jsfmt.spec.js.snap index f138146b6..6394cf7d4 100644 --- a/tests/js/logical-assignment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/logical-assignment/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`invalid.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; + +=====================================output===================================== +c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; + +================================================================================ +`; + exports[`logical-assignment.js format 1`] = ` ====================================options===================================== parsers: ["babel", "typescript"] @@ -26,7 +40,6 @@ c.foo["baz"] ??= result.foo.baz; a.foo.bar().baz &&= result.foo.bar().baz; b.foo.bar().baz ||= result.foo.bar().baz; -c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; b.baz ||= result.baz; c.baz ??= result.baz; @@ -83,7 +96,6 @@ c.foo["baz"] ??= result.foo.baz; a.foo.bar().baz &&= result.foo.bar().baz; b.foo.bar().baz ||= result.foo.bar().baz; -c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; b.baz ||= result.baz; c.baz ??= result.baz; diff --git a/tests/js/logical-assignment/invalid.js b/tests/js/logical-assignment/invalid.js new file mode 100644 index 000000000..55c85a336 --- /dev/null +++ b/tests/js/logical-assignment/invalid.js @@ -0,0 +1 @@ +c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; diff --git a/tests/js/logical-assignment/jsfmt.spec.js b/tests/js/logical-assignment/jsfmt.spec.js index 858ac91aa..70359a9d2 100644 --- a/tests/js/logical-assignment/jsfmt.spec.js +++ b/tests/js/logical-assignment/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "typescript"]); +run_spec(__dirname, ["babel", "typescript"], { + errors: { espree: ["invalid.js"] }, +}); diff --git a/tests/js/logical-assignment/logical-assignment.js b/tests/js/logical-assignment/logical-assignment.js index 2f0274d54..78593b776 100644 --- a/tests/js/logical-assignment/logical-assignment.js +++ b/tests/js/logical-assignment/logical-assignment.js @@ -18,7 +18,6 @@ c.foo["baz"] ??= result.foo.baz; a.foo.bar().baz &&= result.foo.bar().baz; b.foo.bar().baz ||= result.foo.bar().baz; -c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz; b.baz ||= result.baz; c.baz ??= result.baz; diff --git a/tests/js/module-attributes/jsfmt.spec.js b/tests/js/module-attributes/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/module-attributes/jsfmt.spec.js +++ b/tests/js/module-attributes/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/multiparser-css/__snapshots__/jsfmt.spec.js.snap b/tests/js/multiparser-css/__snapshots__/jsfmt.spec.js.snap index e41283286..334e3e958 100644 --- a/tests/js/multiparser-css/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/multiparser-css/__snapshots__/jsfmt.spec.js.snap @@ -250,7 +250,7 @@ const Steps = styled.div\` } \`; -const Steps = styled.div\` +const Steps2 = styled.div\` @media (min-width: \${breakpoints.lg}) { \${Step} { margin-bottom: 90px; @@ -288,7 +288,7 @@ const Steps = styled.div\` } \`; -const Steps = styled.div\` +const Steps2 = styled.div\` @media (min-width: \${breakpoints.lg}) { \${Step} { margin-bottom: 90px; diff --git a/tests/js/multiparser-css/issue-5961.js b/tests/js/multiparser-css/issue-5961.js index 6f2c70f03..7114bfef3 100644 --- a/tests/js/multiparser-css/issue-5961.js +++ b/tests/js/multiparser-css/issue-5961.js @@ -4,7 +4,7 @@ const Steps = styled.div` } `; -const Steps = styled.div` +const Steps2 = styled.div` @media (min-width: ${breakpoints.lg}) { ${Step} { margin-bottom: 90px; diff --git a/tests/js/no-semi-babylon-extensions/jsfmt.spec.js b/tests/js/no-semi-babylon-extensions/jsfmt.spec.js index c5f2d2b9c..18153a1a9 100644 --- a/tests/js/no-semi-babylon-extensions/jsfmt.spec.js +++ b/tests/js/no-semi-babylon-extensions/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ["babel"]); -run_spec(__dirname, ["babel"], { semi: false }); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); +run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } }); diff --git a/tests/js/no-semi/jsfmt.spec.js b/tests/js/no-semi/jsfmt.spec.js index 95d09c15a..98d0477a5 100644 --- a/tests/js/no-semi/jsfmt.spec.js +++ b/tests/js/no-semi/jsfmt.spec.js @@ -1,2 +1,4 @@ -run_spec(__dirname, ["babel", "flow"]); -run_spec(__dirname, ["babel", "flow"], { semi: false }); +const errors = { espree: ["class.js"] }; + +run_spec(__dirname, ["babel", "flow"], { errors }); +run_spec(__dirname, ["babel", "flow"], { semi: false, errors }); diff --git a/tests/js/object-property-comment/jsfmt.spec.js b/tests/js/object-property-comment/jsfmt.spec.js index e3b2b3021..f29fb44bf 100644 --- a/tests/js/object-property-comment/jsfmt.spec.js +++ b/tests/js/object-property-comment/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "flow"]); +run_spec(__dirname, ["babel", "flow"], { + errors: { espree: ["comment.js"] }, +}); diff --git a/tests/js/objects/jsfmt.spec.js b/tests/js/objects/jsfmt.spec.js index 8382eddeb..b113fb835 100644 --- a/tests/js/objects/jsfmt.spec.js +++ b/tests/js/objects/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { + errors: { espree: ["expression.js", "invalid-accessor-generator.js"] }, +}); diff --git a/tests/js/partial-application/jsfmt.spec.js b/tests/js/partial-application/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/partial-application/jsfmt.spec.js +++ b/tests/js/partial-application/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/pipeline-operator/jsfmt.spec.js b/tests/js/pipeline-operator/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/pipeline-operator/jsfmt.spec.js +++ b/tests/js/pipeline-operator/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/private-in/jsfmt.spec.js b/tests/js/private-in/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/private-in/jsfmt.spec.js +++ b/tests/js/private-in/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/quote-props/jsfmt.spec.js b/tests/js/quote-props/jsfmt.spec.js index 9306f203b..cec36fee1 100644 --- a/tests/js/quote-props/jsfmt.spec.js +++ b/tests/js/quote-props/jsfmt.spec.js @@ -1,16 +1,22 @@ +const errors = { espree: ["classes.js"] }; + run_spec(__dirname, ["babel"], { quoteProps: "as-needed", + errors, }); run_spec(__dirname, ["babel"], { quoteProps: "preserve", + errors, }); run_spec(__dirname, ["babel"], { quoteProps: "consistent", + errors, }); run_spec(__dirname, ["babel"], { quoteProps: "consistent", singleQuote: true, + errors, }); diff --git a/tests/js/record/jsfmt.spec.js b/tests/js/record/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/record/jsfmt.spec.js +++ b/tests/js/record/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/rest/jsfmt.spec.js b/tests/js/rest/jsfmt.spec.js index ec33a54c5..98fb7f5ca 100644 --- a/tests/js/rest/jsfmt.spec.js +++ b/tests/js/rest/jsfmt.spec.js @@ -1 +1,4 @@ -run_spec(__dirname, ["babel", "flow"], { trailingComma: "all" }); +run_spec(__dirname, ["babel", "flow"], { + trailingComma: "all", + errors: { espree: true }, +}); diff --git a/tests/js/test-declarations/jsfmt.spec.js b/tests/js/test-declarations/jsfmt.spec.js index d960db115..6298a1fae 100644 --- a/tests/js/test-declarations/jsfmt.spec.js +++ b/tests/js/test-declarations/jsfmt.spec.js @@ -1,2 +1,4 @@ run_spec(__dirname, ["babel", "flow", "typescript"]); -run_spec(__dirname, ["babel", "flow", "typescript"], { arrowParens: "avoid" }); +run_spec(__dirname, ["babel", "flow", "typescript"], { + arrowParens: "avoid", +}); diff --git a/tests/js/throw_expressions/jsfmt.spec.js b/tests/js/throw_expressions/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/throw_expressions/jsfmt.spec.js +++ b/tests/js/throw_expressions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/top-level-await/jsfmt.spec.js b/tests/js/top-level-await/jsfmt.spec.js index 858ac91aa..7d3544f4b 100644 --- a/tests/js/top-level-await/jsfmt.spec.js +++ b/tests/js/top-level-await/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel", "typescript"]); +run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } }); diff --git a/tests/js/trailing-whitespace/jsfmt.spec.js b/tests/js/trailing-whitespace/jsfmt.spec.js index eb85eda6b..4e2e79672 100644 --- a/tests/js/trailing-whitespace/jsfmt.spec.js +++ b/tests/js/trailing-whitespace/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { espree: true }, +}); diff --git a/tests/js/tuple/jsfmt.spec.js b/tests/js/tuple/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/tuple/jsfmt.spec.js +++ b/tests/js/tuple/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests/js/v8_intrinsic/jsfmt.spec.js b/tests/js/v8_intrinsic/jsfmt.spec.js index 8382eddeb..726eaec01 100644 --- a/tests/js/v8_intrinsic/jsfmt.spec.js +++ b/tests/js/v8_intrinsic/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["babel"]); +run_spec(__dirname, ["babel"], { errors: { espree: true } }); diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index b377620e9..de4b7af1d 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -48,6 +48,13 @@ const unstableTests = new Map( }) ); +const espreeDisabledTests = new Set( + [ + // These tests only work for `babel` + "comments-closure-typecast", + ].map((directory) => path.join(__dirname, "../tests/js", directory)) +); + const isUnstable = (filename, options) => { const testFunction = unstableTests.get(filename); @@ -58,18 +65,14 @@ const isUnstable = (filename, options) => { return testFunction(options); }; +// TODO: refactor `disableBabelTS` option to use `errors` const shouldThrowOnFormat = (filename, options) => { - if (options.parser !== "babel-ts") { - return false; - } + const { errors = {}, disableBabelTS } = options; + errors["babel-ts"] = disableBabelTS; - const { disableBabelTS } = options; + const files = errors[options.parser]; - if (disableBabelTS === true) { - return true; - } - - if (Array.isArray(disableBabelTS) && disableBabelTS.includes(filename)) { + if (files === true || (Array.isArray(files) && files.includes(filename))) { return true; } @@ -77,7 +80,9 @@ const shouldThrowOnFormat = (filename, options) => { }; const isTestDirectory = (dirname, name) => - dirname.startsWith(path.join(__dirname, "../tests", name)); + (dirname + path.sep).startsWith( + path.join(__dirname, "../tests", name) + path.sep + ); function runSpec(fixtures, parsers, options) { let { dirname, snippets = [] } = @@ -144,6 +149,15 @@ function runSpec(fixtures, parsers, options) { allParsers.push("babel-ts"); } + if ( + parsers.includes("babel") && + !parsers.includes("espree") && + isTestDirectory(dirname, "js") && + !espreeDisabledTests.has(dirname) + ) { + allParsers.push("espree"); + } + const stringifiedOptions = stringifyOptionsForTitle(options); for (const { name, filename, code, output } of [...files, ...snippets]) { diff --git a/tests_config/utils/compose-options-for-snapshot.js b/tests_config/utils/compose-options-for-snapshot.js index ce9c4193f..88c314db0 100644 --- a/tests_config/utils/compose-options-for-snapshot.js +++ b/tests_config/utils/compose-options-for-snapshot.js @@ -6,6 +6,7 @@ function composeOptionsForSnapshot(baseOptions, parsers) { plugins, filepath, parser, + errors, ...snapshotOptions } = baseOptions; diff --git a/tests_config/utils/stringify-options-for-title.js b/tests_config/utils/stringify-options-for-title.js index c75779a74..c8a798fcb 100644 --- a/tests_config/utils/stringify-options-for-title.js +++ b/tests_config/utils/stringify-options-for-title.js @@ -2,7 +2,7 @@ function stringifyOptions(options) { const string = JSON.stringify(options || {}, (key, value) => - key === "disableBabelTS" || key === "plugins" + key === "disableBabelTS" || key === "plugins" || key === "errors" ? undefined : value === Infinity ? "Infinity" diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index 9036ee217..21fa7cb0a 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -84,7 +84,7 @@ Format options: Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. - --parser + --parser Which parser to use. --print-width The line length where Prettier will try wrap. Defaults to 80. @@ -180,7 +180,7 @@ exports[`show warning with --help not-found (typo) (stderr) 1`] = ` `; exports[`show warning with --help not-found (typo) (stdout) 1`] = ` -"--parser +"--parser Which parser to use. @@ -191,6 +191,7 @@ Valid options: babel-flow Flow babel-ts TypeScript typescript TypeScript + espree JavaScript css CSS less Less scss SCSS @@ -244,7 +245,7 @@ Format options: Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. - --parser + --parser Which parser to use. --print-width The line length where Prettier will try wrap. Defaults to 80. diff --git a/tests_integration/__tests__/__snapshots__/help-options.js.snap b/tests_integration/__tests__/__snapshots__/help-options.js.snap index a7db8cca2..a262c6533 100644 --- a/tests_integration/__tests__/__snapshots__/help-options.js.snap +++ b/tests_integration/__tests__/__snapshots__/help-options.js.snap @@ -361,7 +361,7 @@ exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`; exports[`show detailed usage with --help parser (stderr) 1`] = `""`; exports[`show detailed usage with --help parser (stdout) 1`] = ` -"--parser +"--parser Which parser to use. @@ -372,6 +372,7 @@ Valid options: babel-flow Flow babel-ts TypeScript typescript TypeScript + espree JavaScript css CSS less Less scss SCSS diff --git a/tests_integration/__tests__/__snapshots__/plugin-options-string.js.snap b/tests_integration/__tests__/__snapshots__/plugin-options-string.js.snap index 656238849..d5c3c6014 100644 --- a/tests_integration/__tests__/__snapshots__/plugin-options-string.js.snap +++ b/tests_integration/__tests__/__snapshots__/plugin-options-string.js.snap @@ -20,8 +20,8 @@ exports[` 1`] = ` Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. -- --parser -+ --parser +- --parser ++ --parser Which parser to use. --print-width The line length where Prettier will try wrap. Defaults to 80. diff --git a/tests_integration/__tests__/__snapshots__/plugin-options.js.snap b/tests_integration/__tests__/__snapshots__/plugin-options.js.snap index 4160962f1..641cdbbb9 100644 --- a/tests_integration/__tests__/__snapshots__/plugin-options.js.snap +++ b/tests_integration/__tests__/__snapshots__/plugin-options.js.snap @@ -20,8 +20,8 @@ exports[` 1`] = ` Defaults to false. --jsx-single-quote Use single quotes in JSX. Defaults to false. -- --parser -+ --parser +- --parser ++ --parser Which parser to use. --print-width The line length where Prettier will try wrap. Defaults to 80. @@ -32,7 +32,7 @@ exports[` 1`] = ` exports[`include plugin's parsers to the values of the \`parser\` option\` (stderr) 1`] = `""`; exports[`include plugin's parsers to the values of the \`parser\` option\` (stdout) 1`] = ` -"--parser +"--parser Which parser to use. @@ -43,6 +43,7 @@ Valid options: babel-flow Flow babel-ts TypeScript typescript TypeScript + espree JavaScript css CSS less Less scss SCSS diff --git a/tests_integration/__tests__/__snapshots__/schema.js.snap b/tests_integration/__tests__/__snapshots__/schema.js.snap index de96bf43f..74f5bda0b 100644 --- a/tests_integration/__tests__/__snapshots__/schema.js.snap +++ b/tests_integration/__tests__/__snapshots__/schema.js.snap @@ -162,6 +162,12 @@ This option cannot be used with --range-start and --range-end.", "typescript", ], }, + Object { + "description": "JavaScript", + "enum": Array [ + "espree", + ], + }, Object { "description": "CSS", "enum": Array [ diff --git a/tests_integration/__tests__/__snapshots__/support-info.js.snap b/tests_integration/__tests__/__snapshots__/support-info.js.snap index c137eb3dc..6357b4a6f 100644 --- a/tests_integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests_integration/__tests__/__snapshots__/support-info.js.snap @@ -37,9 +37,11 @@ Object { "babel-ts", "flow", "typescript", + "espree", ], "JavaScript": Array [ "babel", + "espree", "babel-flow", "babel-ts", "flow", @@ -150,6 +152,7 @@ Object { "babel-flow", "babel-ts", "typescript", + "espree", "css", "less", "scss", @@ -313,7 +316,14 @@ exports[`CLI --support-info (stdout) 1`] = ` ], \\"linguistLanguageId\\": 183, \\"name\\": \\"JavaScript\\", - \\"parsers\\": [\\"babel\\", \\"babel-flow\\", \\"babel-ts\\", \\"flow\\", \\"typescript\\"], + \\"parsers\\": [ + \\"babel\\", + \\"espree\\", + \\"babel-flow\\", + \\"babel-ts\\", + \\"flow\\", + \\"typescript\\" + ], \\"since\\": \\"0.0.0\\", \\"tmScope\\": \\"source.js\\", \\"type\\": \\"programming\\", @@ -355,7 +365,14 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"group\\": \\"JavaScript\\", \\"linguistLanguageId\\": 178, \\"name\\": \\"JSX\\", - \\"parsers\\": [\\"babel\\", \\"babel-flow\\", \\"babel-ts\\", \\"flow\\", \\"typescript\\"], + \\"parsers\\": [ + \\"babel\\", + \\"babel-flow\\", + \\"babel-ts\\", + \\"flow\\", + \\"typescript\\", + \\"espree\\" + ], \\"since\\": \\"0.0.0\\", \\"tmScope\\": \\"source.js.jsx\\", \\"type\\": \\"programming\\", @@ -864,6 +881,7 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"since\\": \\"1.4.0\\", \\"value\\": \\"typescript\\" }, + { \\"description\\": \\"JavaScript\\", \\"since\\": \\"2.2.0\\", \\"value\\": \\"espree\\" }, { \\"description\\": \\"CSS\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"css\\" }, { \\"description\\": \\"Less\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"less\\" }, { \\"description\\": \\"SCSS\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"scss\\" }, diff --git a/website/playground/codeSamples.js b/website/playground/codeSamples.js index 74b170a72..0b3e978e4 100644 --- a/website/playground/codeSamples.js +++ b/website/playground/codeSamples.js @@ -1,6 +1,7 @@ export default function (parser) { switch (parser) { case "babel": + case "espree": return [ 'function HelloWorld({greeting = "hello", greeted = \'"World"\', silent = false, onMouseOver,}) {', "", diff --git a/website/playground/markdown.js b/website/playground/markdown.js index ad04510e7..b9bdfc870 100644 --- a/website/playground/markdown.js +++ b/website/playground/markdown.js @@ -38,6 +38,7 @@ function getMarkdownSyntax(options) { case "babel": case "babel-flow": case "flow": + case "espree": return "jsx"; case "babel-ts": case "typescript": diff --git a/website/playground/util.js b/website/playground/util.js index d891a45d4..b41bde90e 100644 --- a/website/playground/util.js +++ b/website/playground/util.js @@ -68,6 +68,7 @@ export function getAstAutoFold(parser) { case "babel-flow": case "babel-ts": case "typescript": + case "espree": case "json": case "json5": case "json-stringify": diff --git a/yarn.lock b/yarn.lock index 50171125e..6edd7dbaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1703,9 +1703,9 @@ acorn-globals@^6.0.0: acorn-walk "^7.1.1" acorn-jsx@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe" - integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ== + version "5.3.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" + integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== acorn-walk@^7.1.1: version "7.2.0" @@ -3625,7 +3625,7 @@ eslint@7.11.0: text-table "^0.2.0" v8-compile-cache "^2.0.3" -espree@^7.3.0: +espree@7.3.0, espree@^7.3.0: version "7.3.0" resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.0.tgz#dc30437cf67947cf576121ebd780f15eeac72348" integrity sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==