Attempt to improve ESLint handling for globals in html files

RESOLVED FIXED in Firefox 62

Status

enhancement
P2
normal
RESOLVED FIXED
Last year
6 months ago

People

(Reporter: standard8, Assigned: standard8)

Tracking

3 Branch
mozilla62
Dependency tree / graph

Firefox Tracking Flags

(firefox62 fixed)

Details

Attachments

(2 attachments)

Assignee

Description

Last year
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
Assignee

Comment 1

Last year
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.
Assignee

Comment 2

Last year
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
Assignee

Updated

Last year
Blocks: 1230193
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+

Comment 7

Last year
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

Comment 8

Last year
bugherder
https://hg.mozilla.org/mozilla-central/rev/70bab1329de0
Status: NEW → RESOLVED
Closed: Last year
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Assignee

Comment 9

Last year
Reopening so that I can hopefully land the second part if phabricator will now let me...
Assignee

Updated

Last year
Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Comment 10

Last year
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

Comment 11

Last year
bugherder
https://hg.mozilla.org/mozilla-central/rev/1bc876a7147b
Status: REOPENED → RESOLVED
Closed: Last yearLast year
Resolution: --- → FIXED
Assignee

Updated

Last year
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.