adding `"sourceType": "module"` flags dynamic imports.
See original GitHub issueTell us about your environment
- ESLint Version: 4.14
- Node Version: 9.3
- npm Version: 5.6
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
module.exports = {
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"no-console": 0,
"semi": ["error", "never"],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
]
}
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
added "sourceType": "module"
to stop flagging import
.
That worked fine but…
What did you expect to happen?
not flag dynamic import line await import
What actually happened? Please include the actual, raw output from ESLint.
Parsing error: Unexpected token import (Fatal)
Note: if I remove the sourceType: module then this stops flagging but of course then the standard import lines do get flagged.
run with atom linter-eslint 8.4 plugin and @std/esm
by @jdalton which enables esm support including dynamic imports.
I understand this is all “new stuff” but come node 10 esm will be native (without using @std/esm
) and
I assume will include dynamic imports.
import path from 'path';
import fs from 'fs';
// import { promisfy as pify } from 'util';
import deepset from 'lodash.set';
import walk from 'walk-filtered';
// const pStat = pify(fs.lstat);
const EXTENSIONS = ['.mjs'];
// rename to file name or remove default in a module
function reDefault(obj, fpath) {
const newObj = {};
Object.keys(obj).forEach((key) => {
if (key !== 'default') newObj[key] = obj[key];
else if (arguments.length === 2) newObj[path.parse(fpath).name] = obj.default;
});
return newObj;
}
async function importFile(directory, relativePath, options, results) {
let module = await import(path.join(directory, relativePath));
if (options.default === 'none') module = reDefault(module)
else module = reDefault(module, relativePath)
// merge result
if (options.collect === 'mergeAll') Object.assign(results, module);
else {
const dirs = path.parse(relativePath).dir;
if (dirs.length) deepset(results, dirs.replace(/\//g, '.'), module);
else Object.assign(results, module);
}
} // end importFile
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
I mean it’s ESLint’s policy too (there’s acorn plugins). It’s a real bummer it’s shrugs all the way down.
In other words,
import()
is not a thing that exists in the language yet (at stage 4, according to acorn’s unfortunate official policy), so it can’t ignore it because it doesn’t understand it in the first place.