Parser Options and ECMAScript Versions
You'll learn how to configure ESLint's parser to correctly understand the modern JavaScript syntax you're actually using in your code.
The Problem ESLint Faces
ESLint doesn't magically know which version of JavaScript you're writing. Are you using ES5 from 2009? ES2015 (ES6) with arrow functions? ES2020 with optional chaining? The parser needs explicit instructions, or it might flag perfectly valid modern syntax as errors.
Think of it like setting your spell-checker's language to English vs. Spanish — same tool, different rules.
The parserOptions Configuration
In your .eslintrc file, the parserOptions object tells ESLint how to interpret your code:
{
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
}
}
ecmaVersion specifies which JavaScript version to parse. You can use year-based numbers (2015, 2020, 2022) or edition numbers (6, 11, 13). Use "latest" to always support the newest approved features.
sourceType tells ESLint whether your code uses ES modules ("module") with import/export, or traditional scripts ("script"). If you're using import statements, you must set this to "module" or ESLint will throw syntax errors.
Why This Matters
Without proper parser options, ESLint might reject syntax like async/await, class fields, or nullish coalescing (??). Conversely, if you set ecmaVersion too low, ESLint won't recognize legitimate modern features.
Match ecmaVersion to the JavaScript features you actually use, and set sourceType based on whether you're writing modules or scripts.
Key Takeaway: Configure parserOptions.ecmaVersion and parserOptions.sourceType in your ESLint config to ensure the parser understands your JavaScript syntax correctly — preventing false errors and enabling proper linting.