Comments (6)
Thank you for the suggestion, it has been implemented and released as part of v7.0.0.
from eslint-plugin-html.
I think you should be able to do something like:
<script type="application/javascript" type="module">
/* eslint-disable */
// Your code
/* eslint-enable */
</script>
from eslint-plugin-html.
It doesn't work because the syntax inside the tag is invalid JavaScript code window.myGlobal.var = {{.MyData}}
Before the comment /* eslint-disable */
takes effect, the parser reports syntax error first.
from eslint-plugin-html.
Please refer to Linting templates
from eslint-plugin-html.
I have read it. But there are a lot of template engines, not only PHP.
And // <?= "\n mydata = " . json_encode($var) . ";" ?>
is quite ugly, and sometimes it's not feasible in other template engines.
If the whole <script>
tag could be disabled from linting, then the code can be simple and clear. Maybe something like:
<!-- eslint-disable -->
<script type="module">
window.myGlobal.var = {{.MyData}}; // here is invalid JS syntax, but it's rendered by backend template engine correctly.
</script>
Is it feasible?
from eslint-plugin-html.
I think the bug here is that invalid JS between eslint-disable
and eslint-enable
trips this module's parser when it should ideally not try to parse anything between such tags:
<script>
/* eslint-disable */
]
/* eslint-enable */
</script>
The bug is reproducible with a regular .js
file too, so I think espree
is not correctly ignoring code between disable/enable sections as it expects the whole file/block to be valid JS, which generally is true for .js
files but it's certainly a problem with templated HTML.
What could work (if eslint-plugin-html
decides to support it) would be support the disable/enable comment as HTML, outside the script block, so the invalid block is not passed to eslint in first place, e.g.
<!-- eslint-disable -->
<script>
]
</script>
<!-- eslint-enable -->
from eslint-plugin-html.
Related Issues (20)
- Failed to load plugin 'html' declared in '.eslintrc.json': createRequire is not a function HOT 1
- Problem with version HOT 1
- Linting non-inline scripts HOT 2
- Failed to load plugin 'html' declared in '.eslintrc ยป eslint-config-wesbos': eslint-plugin-html error: It seems that eslint is not loaded. HOT 2
- Differentially treat specific blocks (use new processor API) HOT 7
- Parsing error: Unterminated string constant when string includes "<body> HOT 2
- type="module", Error: The keyword 'import' is reserved HOT 1
- Eslint-plugin-html installation failed HOT 1
- EOL tests fail on Windows HOT 1
- When `eslint-plugin-html` is extended, rules from other plugins don't work. HOT 4
- Twig handlebars result in parsing errors HOT 1
- You must therefore provide a value for the "parserOptions.project" ...
- `<script type="module">` should support top-level-await HOT 1
- How to ignore `<script>` without specified type? HOT 2
- Flat config support HOT 4
- Including `eslint-plugin-html` in a config for eslint 9 prevents non-html files from being processed HOT 3
- Importing the plugin in a flat config breaks @eslint/config-inspector HOT 1
- Anybody have an example of a flat config file HOT 2
- Include "espree" dependency in package.json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-html.