Replies: 2 comments
-
If you need to enforce ES5 syntax on your files and want your config file to conform as well, you could use |
Beta Was this translation helpful? Give feedback.
0 replies
-
Your other option is to exclude the config file from being linted as var pluginJs = require('@eslint/js');
var pluginN = require('eslint-plugin-n');
var globals = require('globals');
module.exports = [
pluginJs.configs.recommended,
pluginN.configs['flat/recommended-script'],
{
'rules': {
'indent': [
'off',
'tab',
{
SwitchCase: 1,
},
],
'semi': [
'error',
'always',
],
'comma-dangle': [
'error',
'only-multiline',
],
'no-unused-vars': [
'warn',
'local',
],
'space-infix-ops': [
'error',
{
int32Hint: false,
},
],
'no-redeclare': 'off',
'no-useless-return': [
'error',
],
},
files: ["**/*.js"],
+ ignores: ["eslint.config.js"],
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
globals: {
'global': 'readonly',
'Class': 'readonly',
'action': 'writable',
'current': 'writable',
...globals.browser,
...globals.node,
}
}
}
]; You can easily target different configurations for different files, so you don't need to lint every JS file the same way. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to configure ESLint running through VS Code to support an environment running on a EcmaScript 5-based interpreter (Mozilla Rhino).
However setting
ecmaVersion
to5
causes the config file itself to also be parsed targetting ES5, restricting me from e.g. adding the browser & node global objects to be recognized by ESLint, as per the doc page:https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables
The error that I get from trying to use the JS spread syntax (
...
) as suggested is: "Parsing error: Unexpected token .
", related to the first character in the "...globals.browser" line.This is what my eslint.config.js looks like:
It's also not been too long since I migrated to the flat config, so I might be missing something obvious.
For further reference, this is my package.json:
I mostly work with JS scripts which get synchronized with the environment using an external solution, so I had no need to fill in the specific details - past what I needed to sometimes run Quokka (a plugin for VS Code) or ESLint.
I'm not sure what would be the recommended approach - somehow tell ESLint to only apply the ES5 syntax to *.js files that I usually work with, or use a workaround for this issue and keep the eslintrc file in line with the parser's settings for all the other files.
I'd be really grateful for your advice!
Beta Was this translation helpful? Give feedback.
All reactions