-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
174 additions
and
0 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
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,56 @@ | ||
import json | ||
import os | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.NpmRequirement import NpmRequirement | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from coalib.results.Result import Result | ||
|
||
|
||
@linter(executable='sass-lint') | ||
class SASSLintBear: | ||
""" | ||
Check SCSS/SASS code to keep it clean and readable. | ||
""" | ||
|
||
LANGUAGES = {'SCSS', 'SASS'} | ||
REQUIREMENTS = {NpmRequirement('sass-lint', '1.12.1')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax', 'Formatting'} | ||
SEE_MORE = 'https://github.com/sasstools/sass-lint' | ||
|
||
severity_map = {2: RESULT_SEVERITY.MAJOR, | ||
1: RESULT_SEVERITY.NORMAL, | ||
0: RESULT_SEVERITY.INFO} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
sasslint_config: str = ''): | ||
""" | ||
:param sasslint_config: The location of the sass-lint config file. | ||
""" | ||
args = tuple() | ||
if os.path.splitext(filename)[1] == '.scss': | ||
args += ('--syntax=scss',) | ||
if sasslint_config: | ||
args += ('--config=' + sasslint_config,) | ||
args += ('--format=json', '--verbose', '--no-exit', filename) | ||
return args | ||
|
||
def process_output(self, output, filename, file): | ||
if not file or not output: | ||
return | ||
|
||
output = json.loads(output) | ||
|
||
for result in output[0]['messages']: | ||
origin = ( | ||
'{class_name} ({rule})'.format(class_name=type(self).__name__, | ||
rule=result['ruleId']) | ||
if result['ruleId'] is not None else self) | ||
yield Result.from_values( | ||
origin=origin, message=result['message'], | ||
file=filename, line=result['line'], diffs=None, | ||
severity=self.severity_map[result['severity']]) |
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,111 @@ | ||
import os | ||
|
||
from bears.scss.SASSLintBear import SASSLintBear | ||
from coalib.testing.LocalBearTestHelper import verify_local_bear | ||
|
||
# Test examples from http://sass-lang.com/guide | ||
good_sass_file = ''' | ||
nav | ||
ul | ||
list-style: none | ||
margin: 0 | ||
padding: 0 | ||
li | ||
display: inline-block | ||
a | ||
display: block | ||
padding: 6px 12px | ||
text-decoration: none | ||
''' | ||
|
||
bad_sass_file = ''' | ||
nav | ||
ul | ||
margin: 0 | ||
padding: 0 !important | ||
err-style: none | ||
li | ||
display: inline-block | ||
a | ||
display: block | ||
padding: 6px 12px | ||
text-decoration: none | ||
''' | ||
|
||
good_sass_file_with_config = ''' | ||
nav | ||
ul | ||
margin: 0 | ||
padding: 0 !important | ||
li | ||
display: inline-block | ||
''' | ||
|
||
good_scss_file = """ | ||
nav { | ||
ul { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
li { display: inline-block; } | ||
a { | ||
display: block; | ||
padding: 6px 12px; | ||
text-decoration: none; | ||
} | ||
} | ||
""" | ||
|
||
bad_scss_file = """ | ||
nav { | ||
ul { | ||
margin: 0 | ||
padding: 0 | ||
list-style: none | ||
} | ||
li { display: inline-block; } | ||
a { | ||
display: block; | ||
padding: 6px 12px; | ||
text-decoration: none; | ||
} | ||
""" | ||
|
||
test_dir = os.path.join(os.path.dirname(__file__), 'test_files') | ||
|
||
SASSLintBearTest = verify_local_bear( | ||
SASSLintBear, | ||
valid_files=(good_sass_file,), | ||
invalid_files=(bad_sass_file,), | ||
tempfile_kwargs={'suffix': '.sass'}) | ||
|
||
SASSLintBearSCSSTest = verify_local_bear( | ||
SASSLintBear, | ||
valid_files=(good_scss_file,), | ||
invalid_files=(bad_scss_file,), | ||
tempfile_kwargs={'suffix': '.scss'}) | ||
|
||
SASSLintBearConfigTest = verify_local_bear( | ||
SASSLintBear, | ||
valid_files=(good_sass_file_with_config,), | ||
invalid_files=(bad_sass_file,), | ||
tempfile_kwargs={'suffix': '.sass'}, | ||
settings={'sasslint_config': os.path.join(test_dir, 'sass-lint.yml')}) | ||
|
||
SASSLintBearEmptyFileTest = verify_local_bear( | ||
SASSLintBear, | ||
valid_files=('',), | ||
invalid_files=tuple(), | ||
filename=os.path.join(test_dir, 'test.scss'), | ||
tempfile_kwargs={'suffix': '.scss'}, | ||
create_tempfile=False) |
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,4 @@ | ||
# Config file to allow !important to ensure it's loaded | ||
|
||
rules: | ||
no-important: 0 |