Skip to content

Commit

Permalink
Account for default filePath value set by ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Jan 8, 2019
1 parent 59aed40 commit 759ca4c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
const babylonToEspree = require("./babylon-to-espree");
const { parseSync: parse, tokTypes: tt, traverse } = require("@babel/core");

/*
* A filePath may not exist when the --stdin option is used on the command line or
* CLIEngine#executeOnText() is used programmatically. When it doesn't exist, ESLint sets
* the filePath to "<text>".
*
* https://eslint.org/docs/user-guide/command-line-interface#using-stdin
* https://eslint.org/docs/developer-guide/nodejs-api#cliengineexecuteontext
* https://github.com/eslint/eslint/blob/master/lib/cli-engine.js#L177
*/
const ESLINT_DEFAULT_FILEPATH = "<text>";

module.exports = function(code, options) {
const opts = {
sourceType: options.sourceType,
filename: options.filePath,
filename:
options.filePath && options.filePath !== ESLINT_DEFAULT_FILEPATH
? options.filePath
: undefined,
cwd: options.babelOptions.cwd,
root: options.babelOptions.root,
rootMode: options.babelOptions.rootMode,
Expand Down

0 comments on commit 759ca4c

Please sign in to comment.