mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
build(clint): remove redundant checks #18698
Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. See also https://github.com/neovim/neovim/pull/18563
This commit is contained in:
parent
5250d5c1b1
commit
8c2fd65bb1
@ -913,19 +913,9 @@ Don't use spaces inside parentheses. Always use curly braces. >
|
||||
...
|
||||
}
|
||||
|
||||
You must have a space between the `if` and the open parenthesis. You must also
|
||||
have a space between the close parenthesis and the curly brace, if you're
|
||||
using one. >
|
||||
|
||||
if(condition) { // BAD: space missing after IF.
|
||||
if (condition){ // BAD: space missing before {.
|
||||
if (condition) { // GOOD: proper space after IF and before {.
|
||||
|
||||
|
||||
Loops and Switch Statements ~
|
||||
|
||||
Annotate non-trivial fall-through between cases. Empty loop bodies should use
|
||||
`{}` or `continue`.
|
||||
Annotate non-trivial fall-through between cases.
|
||||
|
||||
If not conditional on an enumerated value, switch statements should always
|
||||
have a `default` case (in the case of an enumerated value, the compiler will
|
||||
@ -943,16 +933,6 @@ execute, simply `assert`: >
|
||||
assert(false);
|
||||
}
|
||||
|
||||
Empty loop bodies should use `{}` or `continue`, but not a single semicolon. >
|
||||
|
||||
while (condition) {
|
||||
// Repeat test until it returns false.
|
||||
}
|
||||
for (int i = 0; i < kSomeNumber; i++) {} // GOOD: empty body.
|
||||
while (condition) continue; // GOOD: continue indicates no logic.
|
||||
|
||||
while (condition); // BAD: looks like part of do/while loop.
|
||||
|
||||
Pointer Expressions ~
|
||||
|
||||
No spaces around period or arrow. Pointer operators do not have trailing
|
||||
@ -1009,37 +989,6 @@ expr;`. >
|
||||
return(result); // return is not a function!
|
||||
|
||||
|
||||
Preprocessor Directives ~
|
||||
|
||||
The hash mark that starts a preprocessor directive should always be at the
|
||||
beginning of the line.
|
||||
|
||||
Even when preprocessor directives are within the body of indented code, the
|
||||
directives should start at the beginning of the line.
|
||||
|
||||
Nested directives should add one spaces after the hash mark for each level of
|
||||
indentation.
|
||||
|
||||
// GOOD: directives at beginning of line >
|
||||
if (lopsided_score) {
|
||||
#if DISASTER_PENDING // Correct -- Starts at beginning of line
|
||||
drop_everything();
|
||||
# if NOTIFY // One space after #
|
||||
notify_client();
|
||||
# endif
|
||||
#endif
|
||||
BackToNormal();
|
||||
}
|
||||
|
||||
< // BAD: indented directives >
|
||||
if (lopsided_score) {
|
||||
#if DISASTER_PENDING // Wrong! The "#if" should be at beginning of line
|
||||
drop_everything();
|
||||
#endif // Wrong! Do not indent "#endif"
|
||||
back_to_normal();
|
||||
}
|
||||
|
||||
|
||||
Horizontal Whitespace ~
|
||||
|
||||
Use of horizontal whitespace depends on location. Never put trailing
|
||||
@ -1070,14 +1019,6 @@ whitespace at the end of a line.
|
||||
};
|
||||
<
|
||||
|
||||
Macros ~
|
||||
>
|
||||
#define FI(x) \ // Don't align \'s in macro definitions.
|
||||
foo(); \
|
||||
bar(); \
|
||||
...
|
||||
<
|
||||
|
||||
Loops and Conditionals ~
|
||||
>
|
||||
if (b) { // Space after the keyword in condition.
|
||||
@ -1111,12 +1052,6 @@ Vertical Whitespace ~
|
||||
|
||||
Minimize use of vertical whitespace.
|
||||
|
||||
This is more a principle than a rule: don't use blank lines when you don't
|
||||
have to. In particular, don't put more than one or two blank lines between
|
||||
functions, resist starting functions with a blank line, don't end functions
|
||||
with a blank line, and be discriminating with your use of blank lines inside
|
||||
functions.
|
||||
|
||||
The basic principle is: The more code that fits on one screen, the easier it
|
||||
is to follow and understand the control flow of the program. Of course,
|
||||
readability can suffer from code being too dense as well as too spread out, so
|
||||
|
122
src/clint.py
122
src/clint.py
@ -49,7 +49,6 @@ import re
|
||||
import sre_compile
|
||||
import string
|
||||
import sys
|
||||
import unicodedata
|
||||
import json
|
||||
import collections # for defaultdict
|
||||
|
||||
@ -186,7 +185,6 @@ _ERROR_CATEGORIES = [
|
||||
'readability/increment',
|
||||
'runtime/arrays',
|
||||
'runtime/int',
|
||||
'runtime/invalid_increment',
|
||||
'runtime/memset',
|
||||
'runtime/printf',
|
||||
'runtime/printf_format',
|
||||
@ -194,17 +192,13 @@ _ERROR_CATEGORIES = [
|
||||
'runtime/deprecated',
|
||||
'syntax/parenthesis',
|
||||
'whitespace/alignment',
|
||||
'whitespace/blank_line',
|
||||
'whitespace/braces',
|
||||
'whitespace/comments',
|
||||
'whitespace/empty_conditional_body',
|
||||
'whitespace/empty_loop_body',
|
||||
'whitespace/indent',
|
||||
'whitespace/newline',
|
||||
'whitespace/operators',
|
||||
'whitespace/parens',
|
||||
'whitespace/todo',
|
||||
'whitespace/line_continuation',
|
||||
'whitespace/cast',
|
||||
]
|
||||
|
||||
@ -831,7 +825,6 @@ BRACES = {
|
||||
'(': ')',
|
||||
'{': '}',
|
||||
'[': ']',
|
||||
# '<': '>', C++-specific pair removed
|
||||
}
|
||||
|
||||
|
||||
@ -2037,7 +2030,6 @@ def CheckSpacing(filename, clean_lines, linenum, error):
|
||||
# for the case where the previous line is indented 6 spaces, which
|
||||
# may happen when the initializers of a constructor do not fit into
|
||||
# a 80 column line.
|
||||
exception = False
|
||||
if Match(r' {6}\w', prev_line): # Initializer list?
|
||||
# We are looking for the opening column of initializer list,
|
||||
# which should be indented 4 spaces to cause 6 space indentation
|
||||
@ -2046,39 +2038,6 @@ def CheckSpacing(filename, clean_lines, linenum, error):
|
||||
while (search_position >= 0
|
||||
and Match(r' {6}\w', elided[search_position])):
|
||||
search_position -= 1
|
||||
exception = (search_position >= 0
|
||||
and elided[search_position][:5] == ' :')
|
||||
else:
|
||||
# Search for the function arguments or an initializer list. We
|
||||
# use a simple heuristic here: If the line is indented 4 spaces;
|
||||
# and we have a closing paren, without the opening paren,
|
||||
# followed by an opening brace or colon (for initializer lists)
|
||||
# we assume that it is the last line of a function header. If
|
||||
# we have a colon indented 4 spaces, it is an initializer list.
|
||||
exception = (Match(r' {4}\w[^\(]*\)\s*(const\s*)?(\{\s*$|:)',
|
||||
prev_line)
|
||||
or Match(r' {4}:', prev_line))
|
||||
|
||||
if not exception:
|
||||
error(filename, linenum, 'whitespace/blank_line', 2,
|
||||
'Redundant blank line at the start of a code block '
|
||||
'should be deleted.')
|
||||
# Ignore blank lines at the end of a block in a long if-else
|
||||
# chain, like this:
|
||||
# if (condition1) {
|
||||
# // Something followed by a blank line
|
||||
#
|
||||
# } else if (condition2) {
|
||||
# // Something else
|
||||
# }
|
||||
if linenum + 1 < clean_lines.NumLines():
|
||||
next_line = raw[linenum + 1]
|
||||
if (next_line
|
||||
and Match(r'\s*}', next_line)
|
||||
and next_line.find('} else ') == -1):
|
||||
error(filename, linenum, 'whitespace/blank_line', 3,
|
||||
'Redundant blank line at the end of a code block '
|
||||
'should be deleted.')
|
||||
|
||||
# Next, we complain if there's a comment too near the text
|
||||
commentpos = line.find('//')
|
||||
@ -2215,12 +2174,6 @@ def CheckSpacing(filename, clean_lines, linenum, error):
|
||||
error(filename, linenum, 'whitespace/operators', 4,
|
||||
'Extra space for operator %s' % match.group(1))
|
||||
|
||||
# A pet peeve of mine: no spaces after an if, while, switch, or for
|
||||
match = Search(r' (if\(|for\(|while\(|switch\()', line)
|
||||
if match:
|
||||
error(filename, linenum, 'whitespace/parens', 5,
|
||||
'Missing space before ( in %s' % match.group(1))
|
||||
|
||||
# For if/for/while/switch, the left and right parens should be
|
||||
# consistent about how many spaces are inside the parens, and
|
||||
# there should either be zero or one spaces inside the parens.
|
||||
@ -2288,9 +2241,6 @@ def CheckSpacing(filename, clean_lines, linenum, error):
|
||||
for offset in range(endlinenum + 1,
|
||||
min(endlinenum + 3, clean_lines.NumLines() - 1)):
|
||||
trailing_text += clean_lines.elided[offset]
|
||||
if not Match(r'^[\s}]*[{.;,)<\]]', trailing_text):
|
||||
error(filename, linenum, 'whitespace/braces', 5,
|
||||
'Missing space before {')
|
||||
|
||||
# Make sure '} else {' has spaces.
|
||||
if Search(r'}else', line):
|
||||
@ -2310,18 +2260,6 @@ def CheckSpacing(filename, clean_lines, linenum, error):
|
||||
error(filename, linenum, 'whitespace/braces', 5,
|
||||
'Missing space before }')
|
||||
|
||||
if Search(r'\S {2,}\\$', line):
|
||||
error(filename, linenum, 'whitespace/line_continuation', 5,
|
||||
'Too many spaces before \\, line continuation character must be '
|
||||
'preceded by exactly one space. For “blank lines” '
|
||||
'it is preferred to use the same amount of spaces as preceding '
|
||||
'indent')
|
||||
|
||||
if Match(r'^ +#', line):
|
||||
error(filename, linenum, 'whitespace/indent', 5,
|
||||
'Must not indent preprocessor directives, use 1-space indent '
|
||||
'after the hash')
|
||||
|
||||
cast_line = re.sub(r'^# *define +\w+\([^)]*\)', '', line)
|
||||
match = Search(r'(?<!\bkvec_t)'
|
||||
r'(?<!\bkvec_withinit_t)'
|
||||
@ -2598,65 +2536,6 @@ def CheckBraces(filename, clean_lines, linenum, error):
|
||||
"You don't need a ; after a }")
|
||||
|
||||
|
||||
def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
|
||||
"""Look for empty loop/conditional body with only a single semicolon.
|
||||
|
||||
Args:
|
||||
filename: The name of the current file.
|
||||
clean_lines: A CleansedLines instance containing the file.
|
||||
linenum: The number of the line to check.
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
|
||||
# Search for loop keywords at the beginning of the line. Because only
|
||||
# whitespaces are allowed before the keywords, this will also ignore most
|
||||
# do-while-loops, since those lines should start with closing brace.
|
||||
#
|
||||
# We also check "if" blocks here, since an empty conditional block
|
||||
# is likely an error.
|
||||
line = clean_lines.elided[linenum]
|
||||
matched = Match(r'\s*(for|while|if)\s*\(', line)
|
||||
if matched:
|
||||
# Find the end of the conditional expression
|
||||
(end_line, end_linenum, end_pos) = CloseExpression(
|
||||
clean_lines, linenum, line.find('('))
|
||||
|
||||
# Output warning if what follows the condition expression is a
|
||||
# semicolon. No warning for all other cases, including whitespace or
|
||||
# newline, since we have a separate check for semicolons preceded by
|
||||
# whitespace.
|
||||
if end_pos >= 0 and Match(r';', end_line[end_pos:]):
|
||||
if matched.group(1) == 'if':
|
||||
error(filename, end_linenum,
|
||||
'whitespace/empty_conditional_body', 5,
|
||||
'Empty conditional bodies should use {}')
|
||||
else:
|
||||
error(filename, end_linenum, 'whitespace/empty_loop_body', 5,
|
||||
'Empty loop bodies should use {} or continue')
|
||||
|
||||
|
||||
def GetLineWidth(line):
|
||||
"""Determines the width of the line in column positions.
|
||||
|
||||
Args:
|
||||
line: A string, which may be a Unicode string.
|
||||
|
||||
Returns:
|
||||
The width of the line in column positions, accounting for Unicode
|
||||
combining characters and wide characters.
|
||||
"""
|
||||
if isinstance(line, str):
|
||||
width = 0
|
||||
for uc in unicodedata.normalize('NFC', line):
|
||||
if unicodedata.east_asian_width(uc) in ('W', 'F'):
|
||||
width += 2
|
||||
elif not unicodedata.combining(uc):
|
||||
width += 1
|
||||
return width
|
||||
else:
|
||||
return len(line)
|
||||
|
||||
|
||||
def CheckStyle(filename, clean_lines, linenum, error):
|
||||
"""Checks rules from the 'C++ style rules' section of cppguide.html.
|
||||
|
||||
@ -2710,7 +2589,6 @@ def CheckStyle(filename, clean_lines, linenum, error):
|
||||
|
||||
# Some more style checks
|
||||
CheckBraces(filename, clean_lines, linenum, error)
|
||||
CheckEmptyBlockBody(filename, clean_lines, linenum, error)
|
||||
CheckSpacing(filename, clean_lines, linenum, error)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user