Skip to content

Commit 35e7c64

Browse files
authored
Merge pull request #76 from SublimeLinter/simplify-cmd
Simplify usage of `settings`
2 parents 4aab6a7 + 2b821dd commit 35e7c64

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[flake8]
22
max-line-length = 100
3+
ignore =
4+
W503

linter.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
class Flow(NodeLinter):
2525
"""Provides an interface to flow."""
2626

27+
cmd = ['flow', 'check-contents', '$file', '${args}', '--json']
2728
defaults = {
2829
'selector': 'source.js',
2930
# Allow to bypass the 50 errors cap
30-
'show-all-errors': True
31+
'--show-all-errors': True,
32+
# Run against *all* files regardless of `@flow` comment
33+
'all': False,
34+
# Show flow coverage warnings
35+
'coverage': False
3136
}
3237

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

43-
if not re.search(_flow_comment_re, code) \
44-
and not self._inline_setting_bool('all'):
48+
if not (
49+
re.search(_flow_comment_re, code)
50+
or self.settings.get['all']
51+
):
4552
logger.info("did not find @flow pragma")
4653
return ''
4754

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

51-
coverage = super().run(_build_coverage_cmd(cmd), code) \
52-
if self._inline_setting_bool('coverage') else '{}'
58+
coverage = (
59+
super().run(_build_coverage_cmd(cmd), code)
60+
if self.settings['coverage']
61+
else '{}'
62+
)
5363

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

56-
def cmd(self):
57-
"""
58-
Return the command to execute.
59-
60-
By default, with no command selected, the 'status' command executes.
61-
This starts the server if it is already not started. Once the server
62-
has started, checks are very fast.
63-
"""
64-
command = ['flow']
65-
settings = self.settings
66-
67-
command.extend(['check-contents', '$file'])
68-
69-
if settings['show-all-errors']:
70-
command.append('--show-all-errors')
71-
72-
command.append('--json') # need this for simpler error handling
73-
74-
return command
75-
7666
def _error_to_tuple(self, error):
7767
"""
7868
Map an array of flow error messages to a fake regex match tuple.
@@ -312,11 +302,6 @@ def find_errors(self, output):
312302
repeat(set()))
313303
)
314304

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

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

0 commit comments

Comments
 (0)