Skip to content

Commit

Permalink
bears: Add CSSCombBear
Browse files Browse the repository at this point in the history
CSSCombBear is a coding stye formatter for CSS.
It is based on .csscomb.json file written by the user.

Closes coala#634
  • Loading branch information
Nosferatul committed Sep 20, 2016
1 parent 4926dc0 commit 8be93be
Show file tree
Hide file tree
Showing 2 changed files with 491 additions and 0 deletions.
214 changes: 214 additions & 0 deletions bears/css/CSSCombBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
from coalib.bearlib.abstractions.Linter import linter
from coalib.bears.requirements.NpmRequirement import NpmRequirement
import json


@linter(executable='csscomb',
output_format='corrected',
use_stdout=True,
use_stdin=False,
result_message='Change coding style based on CSS rules written in ' +
'.csscomb.json',
)
class CSSCombBear:
"""
CSScomb is a coding style formatter for CSS.
For more information, consult <https://github.com/csscomb/csscomb.js>.
"""

LANGUAGES = {"CSS"}
REQUIREMENTS = {NpmRequirement('csscomb')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
ASCIINEMA_URL = 'https://asciinema.org/a/bxpke7nizyxdf6mlx6ss4h405'
CAN_FIX = {'Formatting'}

@staticmethod
def create_arguments(filename, file, config_file):
return (filename,)

def generate_config(filename, file,
verbose: bool = True,
remove_empty_rulesets: bool = True,
always_semicolon: bool = True,
color_case: str = "upper",
block_indent: str = "\\t",
color_shorthand: bool = False,
eof_newline: bool = True,
leading_zero: bool = False,
quotes: str = "single",
sort_order_fallback: str = "abc",
space_before_colon: str = " ",
space_after_colon: str = " ",
space_between_declar: str = "\\n",
space_before_o_brace: str = "\\n",
space_after_o_brace: str = "\\n",
space_after_s_delim: str = "\\n",
space_before_s_delim: str = " ",
space_before_c_brace: str = "\\n",
strip_spaces: bool = True,
tab_size: bool = True,
vendor_prefix_align: bool = True,
csscomb_json: str = ""):
"""
:param remove_empty_rulesets:
Remove empty rulesets if exist.
Example:
.a {
color: tomato;
}
.b{}
After using the bear:
.a {
color: tomato;
}
:param always_semicolon:
If true, it will add a semicolon at the end.
Example:
.a {
color; tomato
}
After using the bear:
.a {
color: tomato;
}
:param color_case:
If upper, it will make all colors with upper letters
If lower, it will make all colors with lower letters.
Example(for upper case):
.a {
color: #fff;
}
After using the bear:
.a {
color: #FFF;
}
:param block_indent:
If "\t" it will indent with a tab;
Example:
.a {
color: tomato;
}
After using the bear:
.a {
color: tomato;
}
:param color_shorthand:
If true, it will change the hexa colors into short form.
Example(for true case):
.a {
color: #ffcc00;
}
After using the bear:
.a {
color: #fc0;
}
:param eof_newline:
If true it will add a new line at EOF(end of file).
:param leading_zero:
If false, it will delete the 0 before the dot.
If true, it will add the 0 before the dot.
Example(false case):
.a {
padding: 0.1vh;
font-size: 0.5em;
}
After using the bear:
.a {
padding: .1vh;
font-size: .5em;
}
:param quotes:
Chose between the double quotes or single quotes.
If "single" - single quotes.
If "double" - double quotes.
:param sort_order_fallback:
If "abc", sort the properties alphabetically.
:param space_before_colon:
If " ", it will add a space before colon.
If "", it will remove a space before colon.
:param space_after_colon:
If " ", it will add a space after colon.
If "", it will remove a space after colon.
:param space_between_declar:
If "\n", it will add a line break between declarations.
:param space_before_o_brace:
If "\n", it will add a line break before opening brace.
:param space_after_o_brace:
If "\n", it will add a line break after opening brace.
:param space_after_s_delim:
If "\n", it will add a line break after selector delimiter
Example:
.a, .b{
color: tomato;
}
After using the bear:
.a,
.b{
color: tomato;
}
:param space_before_s_delim:
If " ", it will add a space before selector delimiter.
:param space_before_c_brace:
If "\n", it will add a line break before closing brace.
:param strip_spaces:
If true, it will trim trailing spaces.
:param tab_size:
The size of tabs.
:param vendor_prefix_align:
If true, it will align prefixes.
Example:
.a {
-webkit-border-radius: 3px;
-moz- border-radius: 3px;
border-radius: 3px;
}
After using the bear:
.a {
-hebkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
:param csscomb_json:
The .csscomb.json file, if exists.
"""

options = {"remove-empty-rulesets": remove_empty_rulesets,
"always-semicolon": always_semicolon,
"color-case": color_case,
"block-indent": block_indent,
"eof-newline": eof_newline,
"leading-zero": leading_zero,
"quotes": quotes,
"sort-order-fallback": sort_order_fallback,
"space-before-colon": space_before_colon,
"space-after-colon": space_after_colon,
"space-between-declarations": space_between_declar,
"space-before-opening-brace": space_before_o_brace,
"space-after-opening-brace": space_after_o_brace,
"space-after-selector-delimiter": space_after_s_delim,
"space-before-selector-delimiter": space_before_s_delim,
"space-before-closing-brace": space_before_c_brace,
"strip-spaces": strip_spaces,
"vendor-prefix-align": vendor_prefix_align
}

return json.dumps(options)
Loading

0 comments on commit 8be93be

Please sign in to comment.