Skip to content

Commit

Permalink
Merge pull request #76 from SublimeLinter/simplify-cmd
Browse files Browse the repository at this point in the history
Simplify usage of `settings`
  • Loading branch information
kaste committed Nov 20, 2019
2 parents 4aab6a7 + 2b821dd commit 35e7c64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[flake8]
max-line-length = 100
ignore =
W503
45 changes: 15 additions & 30 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
class Flow(NodeLinter):
"""Provides an interface to flow."""

cmd = ['flow', 'check-contents', '$file', '${args}', '--json']
defaults = {
'selector': 'source.js',
# Allow to bypass the 50 errors cap
'show-all-errors': True
'--show-all-errors': True,
# Run against *all* files regardless of `@flow` comment
'all': False,
# Show flow coverage warnings
'coverage': False
}

__flow_near_re = '`(?P<near>[^`]+)`'
Expand All @@ -40,39 +45,24 @@ def run(self, cmd, code):
"""
_flow_comment_re = r'\@flow'

if not re.search(_flow_comment_re, code) \
and not self._inline_setting_bool('all'):
if not (
re.search(_flow_comment_re, code)
or self.settings.get['all']
):
logger.info("did not find @flow pragma")
return ''

logger.info("found flow pragma!")
check = super().run(cmd, code)

coverage = super().run(_build_coverage_cmd(cmd), code) \
if self._inline_setting_bool('coverage') else '{}'
coverage = (
super().run(_build_coverage_cmd(cmd), code)
if self.settings['coverage']
else '{}'
)

return '[%s,%s]' % (check, coverage)

def cmd(self):
"""
Return the command to execute.
By default, with no command selected, the 'status' command executes.
This starts the server if it is already not started. Once the server
has started, checks are very fast.
"""
command = ['flow']
settings = self.settings

command.extend(['check-contents', '$file'])

if settings['show-all-errors']:
command.append('--show-all-errors')

command.append('--json') # need this for simpler error handling

return command

def _error_to_tuple(self, error):
"""
Map an array of flow error messages to a fake regex match tuple.
Expand Down Expand Up @@ -312,11 +302,6 @@ def find_errors(self, output):
repeat(set()))
)

def _inline_setting_bool(self, s):
"""Get an inline setting as a bool."""
setting = self.settings.get(s)
return setting and setting not in ('False', 'false', '0')


def _traverse_extra(flow_extra):
"""Yield all messages in `flow_extra.message` and `flow_extra.childre.message`."""
Expand Down

0 comments on commit 35e7c64

Please sign in to comment.