Skip to content

Commit

Permalink
Merge pull request #316 from Cobertos/master
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Dec 9, 2021
2 parents 2723a4a + 9645ffa commit 732ab24
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,43 @@ def ensure_plugin_installed(self) -> bool:
# If we fallback to a global installation there is no 'project_root',
# t.i. no auto-selector in that case as well.
project_root = self.context.get('project_root')
if project_root:
# We still need to be careful, in case SL deduced a 'project_root'
# without checking for the 'package.json' explicitly. Basically, a
# happy path for SL core.
manifest_file = os.path.join(project_root, 'package.json')
try:
manifest = read_json_file(manifest_file)
except Exception:
pass
else:
defined_plugins = PLUGINS.keys() & (
manifest.get('dependencies', {}).keys()
| manifest.get('devDependencies', {}).keys()
)
selector = ', '.join(PLUGINS[name] for name in defined_plugins)
if selector and self.view.match_selector(0, selector):
return True
if not project_root:
logger.info("No project_root found.")
if 'executable' in self.settings:
logger.info(
"If 'executable' is set in settings, 'selector' "
"should also manually be specified.")
self.notify_unassign() # Abort linting without popping error dialog
raise PermanentError()

# We still need to be careful, in case SL deduced a 'project_root'
# without checking for the 'package.json' explicitly. Basically, a
# happy path for SL core.
manifest_file = os.path.join(project_root, 'package.json')
try:
manifest = read_json_file(manifest_file)
except Exception as exc:
logger.info(
"Failed to read package.json at project_root '{}' to determine "
"whether or not to eslint this file".format(project_root))
logger.info(exc)
# Occurs even if file not found, so don't notify
self.notify_unassign() # Abort linting without popping error dialog
raise PermanentError()

defined_plugins = PLUGINS.keys() & (
manifest.get('dependencies', {}).keys()
| manifest.get('devDependencies', {}).keys()
)
selector = ', '.join(PLUGINS[name] for name in defined_plugins)
if selector and self.view.match_selector(0, selector):
return True

# Indicate an error which usually can only be solved by changing
# the environment. Silently, do not notify and disturb the user.
self.notify_unassign()
logger.info(
"package.json did not contain dependencies or devDependencies "
"required to lint this file type. Manually set 'selector' to "
"override this behavior, or install the required dependencies.")
self.notify_unassign() # Abort linting without popping error dialog
raise PermanentError()

def on_stderr(self, stderr):
Expand Down

0 comments on commit 732ab24

Please sign in to comment.