Automatically detect eslint-plugin-html, and change default selector settings when found #253
Comments
|
Hi! This is an interesting feature but currently not achievable in 5 lines code. If you have python people in your team, I can guide them. We need two refactorings in core SL and then the feat implementation itself. |
|
I already did one of the two refactorings. |
|
@kaste if you can describe what needs doing, I can try and find someone (or I might be able to do it myself). |
|
@kaste, did you see my comment above? |
|
Oops. I'll try to write it down this week. Sorry. |
|
Okay, how can we tackle this one? Instead of working with file extensions, we can identify the applied syntax of a buffer via selectors or scopes. A typical js file has the main scope We of course need a mapping from selectors to eslint-plugins. Or vice-versa. This depends on if we imagine that for one syntax/selector there are actually multiple plugins available, or again vice-versa one plugin supports multiple syntaxes. So maybe, we have a mapping from
The first method SL will interact with is
which gets a view/buffer with the computed settings and returns a boolean.
We return So, we could, given a view, extend the If we have a Now, we translate this Given a In case we have a starting path, we thus search for Finally, we mutate the selector, maybe like so
and return calling (Implementations wise, we prefer functions over methods. Some of these functions like |
|
I would like to be able to pass full html files to eslint, but I do not want this plugin to try to detect that automatically. I would prefer to be able to set an option in SublimeLinter-eslint that would tell it whether to use the js selector, or the html selector. |
|
@TehShrike You can just set the html selector, the js one, or both manually. What should the option do? |
|
Unset this value: SublimeLinter-eslint/linter.py Line 34 in e24d764 |
Fixes #253 Closes #284 The strategy here is to use a wide `selector` in the beginning and then narrow it down during actual linting. SublimeLinter needs a good `selector` as a **fast** check to match views and installed linters because this first check runs on a shared worker. T.i. we cannot just select *all* views and then decide later. After the first check, it is always possible to abort loud or silently. We do here silently because it's not a configuration error coming from the user but an automatic algorithm bailing out. With this implementation there comes the drawback that we have to flip the previous default behavior. The default behavior was for the linter to run on parts of the buffer marked as `source.js` concurrently. E.g. it did run on the `<script>` tags when viewing a HTML file. However, this default often did not produce good results. I.e. in an HTML file it has no notion of gloabls introduced in one script which are accessible in another script. If the user wants this behavior, she now has to opt in by setting the old selector `'source.js - meta.attribute-with-value'` in the settings on her own. Implementation risks: - We deep import `read_json_file`. It is possible that this import can break since deep imports are not protected by any deprecation policy. - We have two side-effects: `self.notify_unassign()` followed by `raise PermanentError()`. It is possible that in the future we need to signal the same outcome differently.
|
Better now then never. PR is at #287. Would be nice if someone you could test this. |
Fixes #253 Closes #284 The strategy here is to use a wide `selector` in the beginning and then narrow it down during actual linting. SublimeLinter needs a good `selector` as a **fast** check to match views and installed linters because this first check runs on a shared worker. T.i. we cannot just select *all* views and then decide later. After the first check, it is always possible to abort loud or silently. We do here silently because it's not a configuration error coming from the user but an automatic algorithm bailing out. With this implementation there comes the drawback that we have to flip the previous default behavior. The default behavior was for the linter to run on parts of the buffer marked as `source.js` concurrently. E.g. it did run on the `<script>` tags when viewing a HTML file. However, this default often did not produce good results. I.e. in an HTML file it has no notion of gloabls introduced in one script which are accessible in another script. If the user wants this behavior, she now has to opt in by setting the old selector `'source.js - meta.attribute-with-value'` in the settings on her own. Implementation risks: - We deep import `read_json_file`. It is possible that this import can break since deep imports are not protected by any deprecation policy. - We have two side-effects: `self.notify_unassign()` followed by `raise PermanentError()`. It is possible that in the future we need to signal the same outcome differently.
I'm using SublimeText 3.1.1, SublimeLinter 4.6.0, SublimeLinter-eslint 4.1.3.
We first discussed this in #87. I have a multi-developer repository, where we have command line operation, and different editors in use. We really need Sublime & ESLint to work together, so that we can lint html files correctly in all editors and on the command line.
I've discovered that I can get both to work by implementing a user setting of:
Rather than try to get multiple developers to set this up, I'd like a way where SublimeLinter-eslint could detect and set this automatically.
I've looked into Sublime's project settings files, but they seem limited - for example, we don't have one at the moment, so existing developers wouldn't be able to be updated automatically (unlike VSCode's default config options).
The text was updated successfully, but these errors were encountered: