Description
In the codebase I'm looking at, we have plenty of Twig code blocks using the {% twigcode %} with the Javascript code (if statements, includes of other files...), essentially dynamically generating some of the JavaScript content, and linting on those fails with the following error:
Parsing error: Unexpected token
e.g.
$('.select2').select2({'width':'100%'});
{% include('tools/toolsmodal.js.twig') %}
function submit(that, e, options) {
e.preventDefault();
Suggestions on how to handle this setup?
Setup configuration
- ESLint version: 7.25
- eslint-plugin-html version: 8.1.2
- NodeJS version: 23.4
- Operating System name and version: MacOS 16
- ESLint configuration (.eslintrc/eslint.config.js):
module.exports = {
parser: '@babel/eslint-parser',
parserOptions: {
requireConfigFile: false,
},
extends: ['plugin:prettier/recommended', 'eslint:recommended', 'plugin:import/recommended', 'plugin:cypress/recommended'],
settings: {
'import/resolver': 'webpack',
},
plugins: ['babel', 'cypress', 'html'],
globals: {
global: true,
$: true,
trans: true,
enoriaLocale: true,
swal: true,
},
env: {
amd: true,
browser: true,
es6: true,
node: true,
},
ignorePatterns: ['**/js/views//.js'],
rules: {
'max-len': [
'error',
{
code: 250,
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: false,
ignoreTemplateLiterals: false,
},
],
'no-console': 'error',
},
};
Aditional context
Description
In the codebase I'm looking at, we have plenty of Twig code blocks using the {% twigcode %} with the Javascript code (if statements, includes of other files...), essentially dynamically generating some of the JavaScript content, and linting on those fails with the following error:
Parsing error: Unexpected token
e.g.
Suggestions on how to handle this setup?
Setup configuration
module.exports = {
parser: '@babel/eslint-parser',
parserOptions: {
requireConfigFile: false,
},
extends: ['plugin:prettier/recommended', 'eslint:recommended', 'plugin:import/recommended', 'plugin:cypress/recommended'],
settings: {
'import/resolver': 'webpack',
},
plugins: ['babel', 'cypress', 'html'],
globals: {
global: true,
$: true,
trans: true,
enoriaLocale: true,
swal: true,
},
env: {
amd: true,
browser: true,
es6: true,
node: true,
},
ignorePatterns: ['**/js/views//.js'],
rules: {
'max-len': [
'error',
{
code: 250,
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: false,
ignoreTemplateLiterals: false,
},
],
'no-console': 'error',
},
};
Aditional context