Closed Bug 1456762 Opened 2 years ago Closed 2 years ago

Attempt to improve ESLint handling for globals in html files

Categories

(Firefox Build System :: Lint and Formatting, enhancement, P2)

3 Branch
enhancement

Tracking

(firefox62 fixed)

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: standard8, Assigned: standard8)

References

Details

Attachments

(2 files)

Although we are currently using the html plugin for ESLint to parse our html files (mainly chrome tests), it is very hard currently to determine the globals used as we don't know the files that are imported via script tags.

To get around this, we currently have to manually specify import-globals-from.

I think we can make this better. I've opened a request with eslint-plugin-html to see if we can get the script tags inserted as comments into the javascript it generates. We should then be able to pick these up and process them.

Unfortunately as eslint-plugin-html is a processor, the rules don't have access to the original source to get this by themselves.

https://github.com/BenoitZugmeyer/eslint-plugin-html/issues/94
Thanks to a suggestion from BenoitZugmeyer, I've realised that we can use `context.getFilename()` to get the file name, and then do a quick scan for any script tags.

I've got a patch more or less working for this now, so will hopefully post something soon.
I've used htmlparser2 for scanning for the script tags. More reliable than a regexp, and eslint-plugin-html uses it anyway so we aren't including any more packages.

Try push is here: https://treeherder.mozilla.org/#/jobs?repo=try&revision=b181e94f43e2f4d213d89527b373010cc54a402f
Depends on D1643

MozReview-Commit-ID: 84M50HDg0wl
Comment on attachment 8985144 [details]
Bug 1456762 - Add parsing of HTML files to ESLint to discover their script tags and the globals that are imported.

Dave Townsend [:mossop] has approved the revision.

https://phabricator.services.mozilla.com/D1643
Attachment #8985144 - Flags: review+
Comment on attachment 8985145 [details]
Bug 1456762 - Remove now unnecessary import-globals-from statements in html files.

Dave Townsend [:mossop] has approved the revision.

https://phabricator.services.mozilla.com/D1644
Attachment #8985145 - Flags: review+
Pushed by mbanner@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/70bab1329de0
Add parsing of HTML files to ESLint to discover their script tags and the globals that are imported. r=mossop
https://hg.mozilla.org/mozilla-central/rev/70bab1329de0
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Reopening so that I can hopefully land the second part if phabricator will now let me...
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Pushed by mbanner@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1bc876a7147b
Remove now unnecessary import-globals-from statements in html files. r=mossop
https://hg.mozilla.org/mozilla-central/rev/1bc876a7147b
Status: REOPENED → RESOLVED
Closed: 2 years ago2 years ago
Resolution: --- → FIXED
Summary: Attempt to improve handling for globals in html files → Attempt to improve ESLint handling for globals in html files
Version: Version 3 → 3 Branch
You need to log in before you can comment on or make changes to this bug.