Skip to content

Commit

Permalink
Enable plugin against all files if all option is on
Browse files Browse the repository at this point in the history
  • Loading branch information
Pegase745 committed Nov 20, 2019
1 parent 8ba47eb commit 067c014
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions flowtype/commands/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sublime
import sublime_plugin

from ..helpers import is_js_source, find_in_parent_folders, get_flow_bin
from ..helpers import (find_in_parent_folders, get_flow_bin,
has_all_config_enabled, is_js_source)


class BaseCommand(sublime_plugin.TextCommand):
Expand Down Expand Up @@ -57,8 +58,13 @@ def check_thread(self, thread, i=0, dir=1):

def is_enabled(self):
"""Enable the command only on Javascript files and has flow pragma."""
file_path = self.active_window.extract_variables()["file_path"]
content = self.get_content()
pragma = "// @flow" in content or "/* @flow */" in content
pragma = (
"// @flow" in content
or "/* @flow */" in content
or has_all_config_enabled(file_path)
)

return is_js_source(self.view) and pragma

Expand Down
11 changes: 11 additions & 0 deletions flowtype/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import time
from collections import namedtuple
from configparser import RawConfigParser

import sublime

Expand Down Expand Up @@ -144,6 +145,16 @@ def get_flow_bin(file_path):
return flow_bin


def has_all_config_enabled(file_path):
"""Return the presence of `all=true` in flowconfig."""
flowconfig_path = find_in_parent_folders(".flowconfig", file_path)

configParser = RawConfigParser()
configParser.read(os.path.join(flowconfig_path, ".flowconfig"))

return configParser.getboolean("options", "all")


_hdr_pat = re.compile("^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@$")


Expand Down

0 comments on commit 067c014

Please sign in to comment.