Comments (13)
Okay I published a alpha.1
version. It should fix your issue with spaced-comment because it doesn't use comments anymore.
from eslint-plugin-html.
I will look into this, maybe we can use the same scope instance for multiple script tags.
from eslint-plugin-html.
We're also having the same problem under the new version of the plugin - A function or variable defined in an earlier script block and used in a later script block fails in the linter, while working fine in the browser.
I understand that this is a tricky problem, since the reverse is not true :) (i.e., a function declared in script block following that which it is defined in would fail in the browser.)
But I suspect that this is a somewhat common use case.
An option to override the new default would be great. For now we're reverting to the older version.
from eslint-plugin-html.
@BenoitZugmeyer I had a little time to start looking at this. I've created a few tests and started looking at the actual issue. So far here is my current branch:
master...Standard8:module-separation
I've worked up a separation in the parser so that it can identify modules vs scripts. My idea was then to somehow see if it is possible to combine the TransformableString
/ codeParts
sections such that all the scripts were merged together, but the modules were separate.
I think that sort of technique could work for #61 as well.
The other alternative that I thought of would have been to do the separation, but when we call verify on ESLint, see if we could get the globals out and as a result pass them as options into the other script sections, but that didn't look so viable.
I'm not sure if I'll have lots of time to look at this soon, so feel free to pick it up, or if you have ideas let me know and I'll see if I can make some time.
from eslint-plugin-html.
This is a good start, thank you! I worked on this on my side, and I figured out a solution to this issue. Going back to concatenate scripts is not the best approach here, because we'll have the same issues as before, and on top of that I found out it's not how it works in the browser. Two observations:
- Function declaration are not hoisted accross script tags, so this throws a
ReferenceError
:
<script>
foo(); // reference error
</script>
<script>
function foo() {}
</script>
- Modules are also using the
window
as global scope, so this works:
<script>
class Foo {}
</script>
<script type="module">
new Foo();
</script>
My approach would be to parse each script tag to determine which global variables are used and which variables are exported to the global scope, then actually running ESLint rules by specifying which variables are OK to be unused (because they are used in a script tag coming after) or undeclared (because they are declared in a previous script tag).
I commited a WIP on master...share-scope so you can get the idea (I didn't plan to make this public so there is still a lot of bugs and stuff to do), and I'll continue to work on it next week.
from eslint-plugin-html.
@BenoitZugmeyer do you need help with progressing further here? I think I can possibly make some time available in the next week or two.
from eslint-plugin-html.
I'm working on it, I'll try to release something before next week. I think I'll drop support of ESLint < 4.6, because a lot of internal changes have been made in this release, and it would be complicated to support previous versions. I'll prepare a major version of my plugin, with shared scopes and some other minor changes.
from eslint-plugin-html.
Ok great. Thank you! If you want some pre-release testing, I'm quite happy to help, just ping me.
from eslint-plugin-html.
@Standard8 I published v4.0.0-alpha.0, you can try it with npm install eslint-plugin-html@next
. See the v4
branch if you're interested. You will need ESLint 4.7+ !
from eslint-plugin-html.
@BenoitZugmeyer Thanks. This is looking quite good so far. Unfortunately we're now erroring on a lot of our files with:
Invalid location
Error: Invalid location
at locationToIndex (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/TransformableString.js:22:11)
at TransformableString.originalLocation (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/TransformableString.js:121:19)
at remapMessages (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/index.js:236:27)
at pushMessages (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/index.js:98:11)
at Linter.verifyWithSharedScopes (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/index.js:211:5)
at Linter.verify (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/index.js:129:32)
at Linter.verifyAndFix (/Users/mark/dev/gecko/node_modules/eslint/lib/linter.js:1086:29)
at processText (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:175:32)
at processFile (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:219:18)
at fileList.map.fileInfo (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:537:20)
I dumped the message out at the start of remapMessages, and I got:
{ ruleId: 'spaced-comment',
severity: 2,
message: 'Expected space or tab after \'/*\' in comment.',
line: undefined,
column: NaN,
nodeType: 'Block',
source: '',
fix: { range: [ 2, 2 ], text: ' ' } }
{ line: undefined, column: 1 }
The '/*foo' didn't appear in our code, so I assume that's something injected by the plug-in. I turned off spaced-comment and it was then able to lint all the files fine.
I think some of these were files with multiple script segments.
Once the files were being linted, the only thing I noticed that is still an issue is issue #65.
from eslint-plugin-html.
Thank you @BenoitZugmeyer, that looks good (side note: you didn't update @next, but I got it anyway).
The only errors I have now are valid ones (yay!), plus the eol-last issue. The eol-last I'm currently working around with ESLint 4's glob config mechanisms.
from eslint-plugin-html.
@BenoitZugmeyer Can I ask if there's any outstanding issues you know of with the alpha.1 version? We're thinking about using that to get us onto ESLint 4, rather than wait for the release.
from eslint-plugin-html.
Sorry for the wait. I just released the v4, as I can't think of any issue. Let me know how it works for you!
from eslint-plugin-html.
Related Issues (20)
- Error when used with "plugin:@typescript-eslint/recommended-requiring-type-checking" HOT 2
- eslint-plugin-html and prettier have autofix issues with indent changes
- Can use it in the browser? HOT 2
- 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
- Is it possbile to eslint-disable a script(type=module)? HOT 6
- 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
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.