Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with Twig includes in Javascript segments #296

Open
coatpont opened this issue Jan 10, 2025 · 1 comment
Open

Dealing with Twig includes in Javascript segments #296

coatpont opened this issue Jan 10, 2025 · 1 comment

Comments

@coatpont
Copy link

coatpont commented Jan 10, 2025

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

@coatpont
Copy link
Author

I see workarounds are documented here: https://github.com/BenoitZugmeyer/eslint-plugin-html?tab=readme-ov-file#linting-templates-or-php - then I'm turning the issue into a feature request ;-) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant