Skip to content

Commit

Permalink
bears: Change tab_width->indent_size
Browse files Browse the repository at this point in the history
Closes coala#639
  • Loading branch information
AsnelChristian committed Aug 17, 2016
1 parent 25493f6 commit 01486a5
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 53 deletions.
12 changes: 7 additions & 5 deletions bears/c_languages/GNUIndentBear.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import platform
import shlex

from coalib.bearlib import deprecate_settings
from coalib.bearlib.abstractions.Linter import linter
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.requirements.DistributionRequirement import (
Expand All @@ -27,6 +28,7 @@ class GNUIndentBear:
CAN_FIX = {'Formatting'}

@staticmethod
@deprecate_settings(indent_size='tab_width')
def create_arguments(filename, file, config_file,
max_line_length: int=79,
use_spaces: bool=True,
Expand All @@ -45,7 +47,7 @@ def create_arguments(filename, file, config_file,
gnu_style: bool=False,
k_and_r_style: bool=False,
linux_style: bool=False,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_cli_options: str=''):
"""
:param max_line_length:
Expand Down Expand Up @@ -152,16 +154,16 @@ def create_arguments(filename, file, config_file,
Uses Kernighan & Ritchie coding style.
:param linux_style:
Uses Linux coding style.
:param tab_width:
Number of spaces per indent level.
:param indent_size:
Number of spaces per indentation level.
:param indent_cli_options:
Any command line options the indent binary understands. They
will be simply passed through.
"""
indent_options = ("--no-tabs" if use_spaces else "--use-tabs",
"--line-length", str(max_line_length),
"--indent-level", str(tab_width),
"--tab-size", str(tab_width), )
"--indent-level", str(indent_size),
"--tab-size", str(indent_size), )
indent_options += (("--cuddle-do-while",)
if while_and_brace_on_same_line
else ("--dont-cuddle-do-while",))
Expand Down
10 changes: 6 additions & 4 deletions bears/coffee_script/CoffeeLintBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from coalib.bearlib import deprecate_settings
from coalib.bearlib.abstractions.Linter import linter
from coalib.bears.requirements.NpmRequirement import NpmRequirement
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
Expand Down Expand Up @@ -31,6 +32,7 @@ def create_arguments(filename, file, config_file):
return '--reporter=raw', '--stdin', '-f', config_file

@staticmethod
@deprecate_settings(indent_size='tab_width')
def generate_config(filename, file,
max_line_length: int=79,
max_line_length_affect_comments: bool=True,
Expand All @@ -44,7 +46,7 @@ def generate_config(filename, file,
spaces_after_colon: int=1,
enforce_newline_at_EOF: bool=True,
use_spaces: bool=True,
tab_width: int=2,
indent_size: int=2,
number_of_newlines_after_classes: int=2,
prohibit_embedding_javascript_snippet: bool=True,
force_braces: bool=False,
Expand Down Expand Up @@ -100,8 +102,8 @@ def generate_config(filename, file,
:param use_spaces:
Forbids tabs in indentation and applies two spaces for this
purpose.
:param tab_width:
Length of the tab for indentation.
:param indent_size:
Number of spaces per indentation level.
:param number_of_newlines_after_classes:
Determines the number of newlines that separate the class
definition and the rest of the code.
Expand Down Expand Up @@ -258,7 +260,7 @@ class Foo
if use_spaces:
coffee_configs["no_tabs"] = {"level": "error"}
coffee_configs["indentation"] = (
{"value": tab_width, "level": "error"})
{"value": indent_size, "level": "error"})
coffee_configs["no_throwing_strings"] = (
{"level": "error" if not allow_throwing_strings else "ignore"})
coffee_configs["no_trailing_semicolons"] = (
Expand Down
11 changes: 6 additions & 5 deletions bears/general/IndentationBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from coala_utils.string_processing.Core import unescaped_search_for
from coalib.bears.LocalBear import LocalBear
from coalib.bearlib import deprecate_settings
from coalib.bearlib.languages.LanguageDefinition import LanguageDefinition
from coalib.results.SourceRange import SourceRange
from coalib.results.Result import Result, RESULT_SEVERITY
Expand All @@ -17,13 +18,14 @@ class IndentationBear(LocalBear):
CAN_FIX = {'Formatting'}
BEAR_DEPS = {AnnotationBear} # pragma: no cover

@deprecate_settings(indent_size='tab_width')
def run(self,
filename,
file,
dependency_results: dict,
language: str,
use_spaces: bool=True,
tab_width: int=4,
indent_size: int=4,
coalang_dir: str=None):
"""
It is a generic indent bear, which looks for a start and end
Expand Down Expand Up @@ -56,9 +58,8 @@ def run(self,
Language to be used for indentation.
:param use_spaces:
Insert spaces instead of tabs for indentation.
:param tab_width:
No. of spaces to insert for indentation.
Only Applicable if use_spaces is False.
:param indent_size:
Number of spaces per indentation level.
:param coalang_dir:
Full path of external directory containing the coalang
file for language.
Expand Down Expand Up @@ -102,7 +103,7 @@ def run(self,
file, filename,
encaps_pos, annotation_dict)

insert = ' '*tab_width if use_spaces else '\t'
insert = ' '*indent_size if use_spaces else '\t'

no_indent_file = self._get_no_indent_file(file)
new_file = self._get_basic_indent_file(no_indent_file,
Expand Down
8 changes: 5 additions & 3 deletions bears/general/LineLengthBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re

from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.results.Result import Result
Expand All @@ -13,22 +14,23 @@ class LineLengthBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting'}

@deprecate_settings(indent_size='tab_width')
def run(self,
filename,
file,
max_line_length: int=79,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
ignore_length_regex: typed_list(str)=()):
'''
Yields results for all lines longer than the given maximum line length.
:param max_line_length: Maximum number of characters for a line,
the newline character being excluded.
:param tab_width: Number of spaces to show for one tab.
:param indent_size: Number of spaces per indentation level.
:param ignore_length_regex: Lines matching each of the regular
expressions in this list will be ignored.
'''
spacing_helper = SpacingHelper(tab_width)
spacing_helper = SpacingHelper(indent_size)
ignore_regexes = [re.compile(regex) for regex in ignore_length_regex]

for line_number, line in enumerate(file):
Expand Down
10 changes: 6 additions & 4 deletions bears/general/SpaceConsistencyBear.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.results.Diff import Diff
Expand All @@ -11,12 +12,13 @@ class SpaceConsistencyBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_FIX = {'Formatting'}

@deprecate_settings(indent_size='tab_width')
def run(self,
filename,
file,
use_spaces: bool,
allow_trailing_whitespace: bool=False,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
enforce_newline_at_EOF: bool=True):
'''
Check and correct spacing for all textual data. This includes usage of
Expand All @@ -27,12 +29,12 @@ def run(self,
of tabs.
:param allow_trailing_whitespace: Whether to allow trailing whitespace
or not.
:param tab_width: Number of spaces representing one
tab.
:param indent_size: Number of spaces per indentation
level.
:param enforce_newline_at_EOF: Whether to enforce a newline at the
End Of File.
'''
spacing_helper = SpacingHelper(tab_width)
spacing_helper = SpacingHelper(indent_size)
result_texts = []
additional_info_texts = []

Expand Down
8 changes: 5 additions & 3 deletions bears/js/JSONFormatBear.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from collections import OrderedDict

from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.results.Diff import Diff
Expand All @@ -19,15 +20,16 @@ class JSONFormatBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting'}

@deprecate_settings(indent_size='tab_width')
def run(self, filename, file,
json_sort: bool=False,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
escape_unicode: bool=False):
"""
Raises issues for any deviations from the pretty-printed JSON.
:param json_sort: Whether or not keys should be sorted.
:param tab_width: Number of spaces to indent.
:param indent_size: Number of spaces per indentation level.
:param escape_unicode: Whether or not to escape unicode values using
ASCII.
"""
Expand All @@ -43,7 +45,7 @@ def run(self, filename, file,

corrected = json.dumps(json_content,
sort_keys=json_sort,
indent=tab_width,
indent=indent_size,
ensure_ascii=not escape_unicode
).splitlines(True)
# Because of a bug in several python versions we have to correct
Expand Down
8 changes: 5 additions & 3 deletions bears/matlab/MatlabIndentationBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re

from coalib.bearlib import deprecate_settings
from coalib.bears.LocalBear import LocalBear
from coalib.results.Diff import Diff
from coalib.results.Result import Result
Expand All @@ -13,15 +14,16 @@ class MatlabIndentationBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting'}

def run(self, filename, file, tab_width: int=2):
@deprecate_settings(indent_size='tab_width')
def run(self, filename, file, indent_size: int=2):
"""
This bear features a simple algorithm to calculate the right
indentation for Matlab/Octave code. However, it will not handle hanging
indentation or conditions ranging over several lines yet.
:param tab_width: Number of spaces per indentation level.
:param indent_size: Number of spaces per indentation level.
"""
new_file = tuple(self.reindent(file, tab_width))
new_file = tuple(self.reindent(file, indent_size))

if new_file != tuple(file):
wholediff = Diff.from_string_arrays(file, new_file)
Expand Down
8 changes: 5 additions & 3 deletions bears/python/PEP8Bear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import autopep8

from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.bears.requirements.PipRequirement import PipRequirement
Expand All @@ -16,9 +17,10 @@ class PEP8Bear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_FIX = {'Formatting'}

@deprecate_settings(indent_size='tab_width')
def run(self, filename, file,
max_line_length: int=79,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
pep_ignore: typed_list(str)=(),
pep_select: typed_list(str)=(),
local_pep8_config: bool=False):
Expand All @@ -27,7 +29,7 @@ def run(self, filename, file,
functionality of the code in any way.
:param max_line_length: Maximum number of characters for a line.
:param tab_width: Number of spaces per indent level.
:param indent_size: Number of spaces per indentation level.
:param pep_ignore: A list of errors/warnings to ignore.
:param pep_select: A list of errors/warnings to exclusively
apply.
Expand All @@ -37,7 +39,7 @@ def run(self, filename, file,
options = {"ignore": pep_ignore,
"select": pep_select,
"max_line_length": max_line_length,
"indent_size": tab_width}
"indent_size": indent_size}

corrected = autopep8.fix_code(''.join(file),
apply_config=local_pep8_config,
Expand Down
10 changes: 6 additions & 4 deletions bears/python/PyImportSortBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from isort import SortImports

from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.bears.requirements.PipRequirement import PipRequirement
Expand All @@ -17,6 +18,7 @@ class PyImportSortBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_FIX = {'Formatting'}

@deprecate_settings(indent_size='tab_width')
def run(self, filename, file,
use_parentheses_in_import: bool=True,
force_alphabetical_sort_in_import: bool=False,
Expand All @@ -38,7 +40,7 @@ def run(self, filename, file,
force_single_line_imports: bool=True,
sort_imports_by_length: bool=False,
use_spaces: bool=True,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
forced_separate_imports: typed_list(str)=(),
isort_multi_line_output: int=4,
known_first_party_imports: typed_list(str)=(),
Expand Down Expand Up @@ -112,8 +114,8 @@ def run(self, filename, file,
Set to true to sort imports by length instead of alphabetically.
:param use_spaces:
True if spaces are to be used instead of tabs.
:param tab_width:
Number of spaces per indent level.
:param indent_size:
Number of spaces per indentation level.
:param forced_separate_imports:
A list of modules that you want to appear in their own separate
section.
Expand Down Expand Up @@ -163,7 +165,7 @@ def run(self, filename, file,
force_grid_wrap=force_grid_wrap_imports,
force_single_line=force_single_line_imports,
length_sort=sort_imports_by_length,
indent="Tab" if use_spaces == False else tab_width,
indent="Tab" if use_spaces == False else indent_size,
forced_separate=forced_separate_imports,
multi_line_output=isort_multi_line_output,
known_first_party=known_first_party_imports,
Expand Down
10 changes: 6 additions & 4 deletions bears/python/YapfBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from yapf.yapflib.yapf_api import FormatFile

from coalib.bearlib import deprecate_settings
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.bears.requirements.PipRequirement import PipRequirement
Expand All @@ -24,9 +25,10 @@ class YapfBear(LocalBear):
CAN_FIX = {'Formatting'}

# TODO Add coalesce_brackets once supported by yapf
@deprecate_settings(indent_size='tab_width')
def run(self, filename, file,
max_line_length: int=79,
tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
indent_size: int=SpacingHelper.DEFAULT_TAB_WIDTH,
allow_multiline_lambdas: bool=False,
blank_line_before_nested_class_or_def: bool=False,
continuation_tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
Expand All @@ -46,8 +48,8 @@ def run(self, filename, file,
"""
:param max_line_length:
Maximum number of characters for a line.
:param tab_width:
Number of spaces per indent level.
:param indent_size:
Number of spaces per indentation level.
:param allow_multiline_lambdas:
Allows lambdas to be formatted on more than one line.
:param blank_line_before_nested_class_or_def:
Expand Down Expand Up @@ -93,7 +95,7 @@ def run(self, filename, file,

options = """
[style]
indent_width = {tab_width}
indent_width = {indent_size}
column_limit = {max_line_length}
allow_multiline_lambdas = {allow_multiline_lambdas}
continuation_indent_width = {continuation_tab_width}
Expand Down
Loading

0 comments on commit 01486a5

Please sign in to comment.