-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug solving sprint #747
Bug solving sprint #747
Changes from all commits
4f01f11
5a4c5c2
241726c
4e5a4d8
dc3d2ec
ae85d9d
c24be59
6f685f4
138c7aa
600ba0b
f8c00cd
35140b4
bfd61fb
fa70e92
22cdc8a
db8a2de
ee34cdc
c60e9f5
5c72d4e
8a3d7fd
b3be8f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.bears.requirements.GemRequirement import GemRequirement | ||
|
||
|
||
@linter(executable='puppet-lint', | ||
output_format='regex', | ||
output_regex=r'(?P<line>\d+):(?P<column>\d+):' | ||
r'(?P<severity>warning|error):(?P<message>.+)') | ||
class PuppetLintBear: | ||
''' | ||
Check and correct puppet configuration files using ``puppet-lint``. | ||
|
||
See <http://puppet-lint.com/> for details about the tool. | ||
''' | ||
|
||
LANGUAGES = {"Puppet"} | ||
REQUIREMENTS = {GemRequirement('puppet-lint', '2')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_FIX = {'Syntax'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return ('--log-format', "%{line}:%{column}:%{kind}:%{message}", | ||
filename) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ class CSSLintBear: | |
problems or inefficiencies. | ||
""" | ||
LANGUAGES = {"CSS"} | ||
REQUIREMENTS = {NpmRequirement('csslint', '0')} | ||
REQUIREMENTS = {NpmRequirement('csslint', '1')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import re | ||
|
||
from coalib.bearlib import deprecate_settings | ||
from coalib.bears.LocalBear import LocalBear | ||
from coalib.results.Result import RESULT_SEVERITY, Result | ||
|
@@ -10,53 +12,28 @@ class KeywordBear(LocalBear): | |
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Documentation'} | ||
|
||
@deprecate_settings(keywords_case_sensitive='cs_keywords') | ||
def run(self, | ||
filename, | ||
file, | ||
keywords_case_insensitive: list, | ||
keywords_case_sensitive: list=()): | ||
@deprecate_settings(keywords='ci_keywords') | ||
def run(self, filename, file, keywords: list): | ||
''' | ||
Checks the code files for given keywords. | ||
|
||
:param keywords_case_insensitive: | ||
:param keywords: | ||
A list of keywords to search for (case insensitive). | ||
Usual examples are TODO and FIXME. | ||
:param keywords_case_sensitive: | ||
A list of keywords to search for (case sensitive). | ||
''' | ||
results = list() | ||
|
||
for i in range(len(keywords_case_insensitive)): | ||
keywords_case_insensitive[i] = keywords_case_insensitive[i].lower() | ||
keywords_regex = re.compile( | ||
'(' + '|'.join(re.escape(key) for key in keywords) + ')', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this not result in having a first empty group? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no as per explanation on gitter |
||
re.IGNORECASE) | ||
|
||
for line_number, line in enumerate(file): | ||
for keyword in keywords_case_sensitive: | ||
results += self.check_line_for_keyword(line, | ||
filename, | ||
line_number, | ||
keyword) | ||
|
||
for keyword in keywords_case_insensitive: | ||
results += self.check_line_for_keyword(line.lower(), | ||
filename, | ||
line_number, | ||
keyword) | ||
|
||
return results | ||
|
||
def check_line_for_keyword(self, line, filename, line_number, keyword): | ||
pos = line.find(keyword) | ||
if pos != -1: | ||
return [Result.from_values( | ||
origin=self, | ||
message="The line contains the keyword `{}`." | ||
.format(keyword), | ||
file=filename, | ||
line=line_number+1, | ||
column=pos+1, | ||
end_line=line_number+1, | ||
end_column=pos+len(keyword)+1, | ||
severity=RESULT_SEVERITY.INFO)] | ||
|
||
return [] | ||
for keyword in keywords_regex.finditer(line): | ||
yield Result.from_values( | ||
origin=self, | ||
message="The line contains the keyword '{}'." | ||
.format(keyword.group()), | ||
file=filename, | ||
line=line_number + 1, | ||
column=keyword.start() + 1, | ||
end_line=line_number + 1, | ||
end_column=keyword.end() + 1, | ||
severity=RESULT_SEVERITY.INFO) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ class ESLintBear: | |
""" | ||
|
||
LANGUAGES = {"JavaScript", "JSX"} | ||
REQUIREMENTS = {NpmRequirement('eslint', '2')} | ||
REQUIREMENTS = {NpmRequirement('eslint', '3')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
|
@@ -48,7 +48,7 @@ def generate_config(filename, file): | |
return '{"extends": "eslint:recommended"}' | ||
|
||
def process_output(self, output, filename, file): | ||
if not file: | ||
if not file or not output: | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we'll rather want to trow a warning in that case with a nice message what's wrong instead of silently approving that all code is good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i.e. the message will probably have a similar structure, make a regex and match the message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, but I do not have stderr here. SO, the message is empty ... |
||
|
||
output = json.loads(output) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,11 @@ class JSHintBear: | |
CAN_DETECT = {'Formatting', 'Syntax', 'Complexity', 'Unused Code'} | ||
|
||
@staticmethod | ||
@deprecate_settings(cyclomatic_complexity='maxcomplexity', | ||
@deprecate_settings(es_version='use_es6_syntax', | ||
javascript_strictness=( | ||
"allow_global_strict", | ||
lambda x: "global" if x else True), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah your lambdas aren't covered by the tests |
||
cyclomatic_complexity='maxcomplexity', | ||
allow_unused_variables=('prohibit_unused', negate), | ||
max_parameters='maxparams', | ||
allow_missing_semicolon='allow_missing_semicol', | ||
|
@@ -89,20 +93,19 @@ def generate_config(filename, file, | |
allow_debugger: bool=False, | ||
allow_assignment_comparisions: bool=False, | ||
allow_eval: bool=False, | ||
allow_global_strict: bool=False, | ||
allow_increment: bool=False, | ||
allow_proto: bool=False, | ||
allow_scripturls: bool=False, | ||
allow_singleton: bool=False, | ||
allow_this_statements: bool=False, | ||
allow_with_statements: bool=False, | ||
use_mozilla_extension: bool=False, | ||
javascript_strictness: bool_or_str=True, | ||
allow_noyield: bool=False, | ||
allow_eqnull: bool=False, | ||
allow_last_semicolon: bool=False, | ||
allow_func_in_loop: bool=False, | ||
allow_expr_in_assignments: bool=False, | ||
use_es6_syntax: bool=False, | ||
use_es3_array: bool=False, | ||
environment_mootools: bool=False, | ||
environment_couch: bool=False, | ||
|
@@ -132,7 +135,7 @@ def generate_config(filename, file, | |
allow_variable_shadowing: bool_or_str=False, | ||
allow_unused_variables: bool_or_str=False, | ||
allow_latedef: bool_or_str=False, | ||
es_version: int=5, | ||
es_version: bool_or_int=5, | ||
jshint_config: str=""): | ||
""" | ||
:param allow_bitwise_operators: | ||
|
@@ -184,9 +187,6 @@ def generate_config(filename, file, | |
:param allow_eval: | ||
This options suppresses warnings about the use of ``eval`` | ||
function. | ||
:param allow_global_strict: | ||
This option suppresses warnings about the use of global strict | ||
mode. | ||
:param allow_increment: | ||
This option suppresses warnings about the use of unary increment | ||
and decrement operators. | ||
|
@@ -209,6 +209,14 @@ def generate_config(filename, file, | |
:param use_mozilla_extension: | ||
This options tells JSHint that your code uses Mozilla JavaScript | ||
extensions. | ||
:param javascript_strictness: | ||
Determines what sort of strictness to use in the JavaScript code. | ||
The possible options are: | ||
|
||
- "global" - there must be a ``"use strict";`` at global level | ||
- "implied" - lint the code as if there is a ``"use strict";`` | ||
- "False" - disable warnings about strict mode | ||
- "True" - there must be a ``"use strict";`` at function level | ||
:param allow_noyield: | ||
This option suppresses warnings about generator functions with no | ||
``yield`` statement in them. | ||
|
@@ -225,8 +233,6 @@ def generate_config(filename, file, | |
:param use_es3_array: | ||
This option tells JSHintBear ES3 array elision elements, or empty | ||
elements are used. | ||
:param use_es3_array: | ||
This option tells JSHint ECMAScript 6 specific syntax is used. | ||
:param environment_mootools: | ||
This option defines globals exposed by the Mootools. | ||
:param environment_couch: | ||
|
@@ -308,6 +314,12 @@ def generate_config(filename, file, | |
This option is used to specify the ECMAScript version to which the | ||
code must adhere to. | ||
""" | ||
# Assume that when es_version is bool, it is intended for the | ||
# deprecated use_es6_version | ||
if es_version is True: | ||
es_version = 6 | ||
elif es_version is False: | ||
es_version = 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually you can put this into the conversion routine/annotation for es_version huh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not complete. If I put it there, people can still do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the conversion run on any given valu? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't gone into the dept of reading it and understanding what it does On Sat, Sep 3, 2016 at 9:36 PM, Lasse Schuirmann [email protected]
|
||
if not jshint_config: | ||
options = {"bitwise": not allow_bitwise_operators, | ||
"freeze": not allow_prototype_overwrite, | ||
|
@@ -329,7 +341,7 @@ def generate_config(filename, file, | |
"debug": allow_debugger, | ||
"boss": allow_assignment_comparisions, | ||
"evil": allow_eval, | ||
"globalstrict": allow_global_strict, | ||
"strict": javascript_strictness, | ||
"plusplus": allow_increment, | ||
"proto": allow_proto, | ||
"scripturl": allow_scripturls, | ||
|
@@ -342,7 +354,6 @@ def generate_config(filename, file, | |
"lastsemic": allow_last_semicolon, | ||
"loopfunc": allow_func_in_loop, | ||
"expr": allow_expr_in_assignments, | ||
"esnext": use_es6_syntax, | ||
"elision": use_es3_array, | ||
"mootools": environment_mootools, | ||
"couch": environment_couch, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ class MarkdownBear: | |
""" | ||
|
||
LANGUAGES = {"Markdown"} | ||
REQUIREMENTS = {NpmRequirement('remark', '3')} | ||
REQUIREMENTS = {NpmRequirement('remark-cli', '2')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import subprocess | ||
import sys | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.bears.requirements.NpmRequirement import NpmRequirement | ||
|
||
|
@@ -13,11 +16,35 @@ class AlexBear: | |
writing. | ||
""" | ||
LANGUAGES = {"Natural Language"} | ||
REQUIREMENTS = {NpmRequirement('alex', '2')} | ||
REQUIREMENTS = {NpmRequirement('alex', '3')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
|
||
@classmethod | ||
def check_prerequisites(cls): | ||
parent_prereqs = super().check_prerequisites() | ||
if parent_prereqs is not True: # pragma: no cover | ||
return parent_prereqs | ||
|
||
incorrect_pkg_msg = ( | ||
"Please ensure that the package that has been installed is the " | ||
"one to 'Catch insensitive, inconsiderate writing'. This can be " | ||
"verified by running `alex --help` and seeing what it does.") | ||
try: | ||
output = subprocess.check_output(("alex", "--help"), | ||
stderr=subprocess.STDOUT) | ||
except (OSError, subprocess.CalledProcessError): | ||
return ("The `alex` package could not be verified. " + | ||
incorrect_pkg_msg) | ||
else: | ||
output = output.decode(sys.getfilesystemencoding()) | ||
if "Catch insensitive, inconsiderate writing" in output: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wooorm is this workaround ok or would you suggest something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sils1297 would it work to check if 'which alex', resolving symlinks, yields an '.js' file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AbdealiJK ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the current method to be cleaner as compared to following symlinks. Is there any downside of the current way ? Is there a plan to change the slogan in the help ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, not to my knowledge. And there are no plans to change it! |
||
return True | ||
else: | ||
return ("The `alex` package that's been installed seems to " | ||
"be incorrect. " + incorrect_pkg_msg) | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return filename, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.bears.requirements.PipRequirement import PipRequirement | ||
|
||
|
||
@linter(executable='scspell', | ||
use_stderr=True, | ||
output_format='regex', | ||
output_regex=r'(?P<filename>.*):(?P<line>.\d*):\s*(?P<message>.*)') | ||
class SpellCheckBear: | ||
""" | ||
Lints files to check for incorrect spellings using ``scspell``. | ||
|
||
See <https://pypi.python.org/pypi/scspell> for more information. | ||
""" | ||
LANGUAGES = {"Natural Language"} | ||
REQUIREMENTS = {PipRequirement('scspell3k', '2.0')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Spelling'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asciinema URL missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return '--report-only', filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an asciinema URL or file an issue about making one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#784