Ask questionsPossible to use swc with / for eslint?
eslint
is a big part of our largest project's build times and it's currently configured to use babel-parser.
To get rid of babel entirely it'd be nice to be able to get eslint to use swc somehow: https://eslint.org/docs/user-guide/configuring#specifying-parser
On an unrelated note, with swc 1.0.21 the project finally builds and seems to mostly work (I haven't looked to closely yet). Thank you for your hard work and the quick responses to bug reports, it's much appreciated!
Answer
questions
kapouer
I just tried but it seems eslint is expecting something a little bit different than the format returned by
exports.parse = function(str, opts) {
return {
ast: require('@swc/core').parseSync(str.toString(), {})
};
};
EDIT2: this is what eslint expects: https://eslint.org/docs/developer-guide/working-with-custom-parsers
To test with eslint, just create a swcparser.js
file at the root of your project,
then put this into your project's .eslintrc
:
{"parser": "./swcparser.js"}
Then to debug,
DEBUG=eslint:* eslint somefile.js
Using @swc/core 1.1.6 and eslint 6.7.2:
echo "var a = 1;" | eslint --stdin
eslint:linter Parsing error: AST is missing the tokens array.
eslint:linter Error: AST is missing the tokens array.
as expected, since the tokens array is indeed not where it is supposed to be.