lib/tailor/spacing.rb in tailor-0.1.3 vs lib/tailor/spacing.rb in tailor-0.1.4

- old
+ new

@@ -7,19 +7,19 @@ # line in a file. The real intent here is to mix in to the FileLine class. module Spacing # TODO: Add skipping of comment lines. SPACING_CONDITIONS = { :more_than_one_space_after_comma => [ - /\,\x20{2,}(\w|'|"|:).*((?:(?!#\s*)).)*$/, + /,\x20{2,}(\w|'|"|:).*((?:(?!#\s*)).)*$/, "[Spacing] Line has a comma with > 1 space after it" ], :no_space_after_comma => [ - /\,\x20{0}\S/, + /,\x20{0}\S/, "[Spacing] Line has a comma with 0 spaces after it" ], :space_before_comma => [ - /\S\x20+\,/, + /\S\x20+,/, "[Spacing] Line has at least one space before a comma" ], :space_after_open_parenthesis => [ /\(\x20+/, "[Spacing] Line has a '(' with spaces after it" @@ -65,11 +65,10 @@ /^.*\?.*\w((\x20{0}|\x20{2,}):(?!:)|[^:|\[]:(\x20{0}|\x20{2,})\w)/, "[Spacing] Line contains ternary ':' with not 1 space around it" ] } - ## # Detect spacing problems around all predefined bad cases. # # @return [Number] The number of problems discovered during detection. def spacing_problems problem_count = 0 @@ -83,16 +82,16 @@ problem_count += 1 @line_problem_count += 1 print_problem values[1] end end + problem_count end - ## # Checks to see if there's whitespace at the end of the line. Prints the - # number of whitespaces at the end of the line. + # number of whitespaces at the end of the line. # # @return [Boolean] Returns true if there's whitespace at the end of the # line. =begin def trailing_whitespace? @@ -105,31 +104,29 @@ end return false end =end - ## # Checks to see if the line has trailing whitespace at the end of it. Note - # that this excludes empty lines that have spaces on them! + # that this excludes empty lines that have spaces on them! # # @return [Number] Returns the number of trailing spaces at the end of the # line. def trailing_whitespace_count spaces = self.scan(/(\x20+|\x09+)$/) if spaces.first.eql? nil return 0 end - return spaces.first.first.length + spaces.first.first.length end module_function :trailing_whitespace_count - ## # Checks to see if there's no spaces before a given string. If the line - # being checked is a method with a question mark at the end of it, this - # skips checking the line. + # being checked is a method with a question mark at the end of it, this + # skips checking the line. # # @param [String] string The string to check for spaces before. # @return [Boolean] True if there are no spaces before the string. def no_space_before? string # Get out if the check is for a '?' and that's part of a method name. @@ -160,11 +157,10 @@ end result end - ## # Checks to see if there's no spaces after a given string. # # @param [String] string The string to check for spaces after. # @return [Boolean] True if there are no spaces after the string. def no_space_after? string @@ -201,11 +197,10 @@ end result end - ## # Gets the number of spaces after a string. # # @param [String] string The string to check for spaces after. # @return [Array<Number>] An array that holds the number of spaces after # every time the given string appears in a line. @@ -215,29 +210,28 @@ return false end right_side_match = Regexp.new(Regexp.escape(string) + '\x20*') - occurences = self.scan(right_side_match) + occurrences = self.scan(right_side_match) results = [] - occurences.each do |o| + occurrences.each do |o| string_spaces = o.sub(string, '') results << string_spaces.size end results end - ## # Checks to see if the line contains a method name with a ?. # # @return [Boolean] True if the line contains a method line include?. def question_mark_method? if self.scan(/[a-zA-Z|_]\w*\?/).empty? return false end - return true + true end end -end \ No newline at end of file +end