-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/99_credential_storage
- Loading branch information
Showing
9 changed files
with
215 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ script: | |
|
||
notifications: | ||
email: | ||
on_success: never | ||
on_success: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
"""ESLint plugin for zazu.""" | ||
import zazu.styler | ||
zazu.util.lazy_import(locals(), [ | ||
'click', | ||
'json', | ||
'os', | ||
'subprocess' | ||
]) | ||
|
||
__author__ = "Patrick Moore" | ||
__copyright__ = "Copyright 2018" | ||
|
||
|
||
class ESLintStyler(zazu.styler.Styler): | ||
"""ESLint plugin for code styling.""" | ||
|
||
def style_string(self, string, filepath): | ||
"""Fix a string to be within style guidelines. | ||
Args: | ||
string (str): the string to style | ||
filepath (str): the filepath of the file being styled | ||
Returns: | ||
Styled string. | ||
""" | ||
|
||
eslint = 'eslint' | ||
cwd = os.path.normpath(os.getcwd()) | ||
dirname = os.path.normpath(os.path.dirname(filepath)) | ||
loop_count = 0 | ||
|
||
local_eslint = os.path.join('node_modules', 'eslint', 'bin', 'eslint.js') | ||
|
||
while True and loop_count < 100: | ||
loop_count = loop_count + 1 | ||
maybe_eslint = os.path.join(dirname, local_eslint) | ||
|
||
if os.path.isfile(maybe_eslint): | ||
eslint = maybe_eslint | ||
break | ||
elif os.path.realpath(dirname) == cwd: | ||
# Stop searching for eslint above current working directory | ||
# An invalid filepath should break-out here | ||
break | ||
elif os.path.realpath(dirname) == os.path.normpath('/'): | ||
# Stop searching when dirname and maybe_eslint are same | ||
# This should be the filesystem root | ||
break | ||
|
||
dirname = os.path.normpath(os.path.join(dirname, '..')) | ||
|
||
if loop_count >= 100: | ||
raise click.ClickException('Unable to find eslint.js') | ||
|
||
args = [eslint, '-f', 'json', '--fix-dry-run', '--stdin', '--stdin-filename', filepath] + self.options | ||
try: | ||
p = subprocess.Popen(args=args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | ||
results, _ = p.communicate(string) | ||
except OSError: | ||
raise click.ClickException('Unable to find {}'.format(args[0])) | ||
|
||
return json.loads(results)[0].get('output', string) | ||
|
||
@staticmethod | ||
def default_extensions(): | ||
"""Return the list of file extensions that are compatible with this Styler.""" | ||
return ['*.js'] | ||
|
||
@staticmethod | ||
def type(): | ||
"""Return the string type of this Styler.""" | ||
return 'eslint' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters