mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
clint: remove CheckAltTokens()
- These "alternative tokens" keywords are for C++, not C. - The check sometimes has false positives, e.g. `compl` is a variable name in edit.c
This commit is contained in:
65
src/clint.py
65
src/clint.py
@@ -234,38 +234,6 @@ _ERROR_CATEGORIES = [
|
||||
# All entries here should start with a '-' or '+', as in the --filter= flag.
|
||||
_DEFAULT_FILTERS = ['-build/include_alpha']
|
||||
|
||||
# We used to check for high-bit characters, but after much discussion we
|
||||
# decided those were OK, as long as they were in UTF-8 and didn't represent
|
||||
# hard-coded international strings, which belong in a separate i18n file.
|
||||
|
||||
# Alternative tokens and their replacements. For full list, see section 2.5
|
||||
# Alternative tokens [lex.digraph] in the C++ standard.
|
||||
#
|
||||
# Digraphs (such as '%:') are not included here since it's a mess to
|
||||
# match those on a word boundary.
|
||||
_ALT_TOKEN_REPLACEMENT = {
|
||||
'and': '&&',
|
||||
'bitor': '|',
|
||||
'or': '||',
|
||||
'xor': '^',
|
||||
'compl': '~',
|
||||
'bitand': '&',
|
||||
'and_eq': '&=',
|
||||
'or_eq': '|=',
|
||||
'xor_eq': '^=',
|
||||
'not': '!',
|
||||
'not_eq': '!='
|
||||
}
|
||||
|
||||
# Compile regular expression that matches all the above keywords. The "[ =()]"
|
||||
# bit is meant to avoid matching these keywords outside of boolean expressions.
|
||||
#
|
||||
# False positives include C-style multi-line comments and multi-line strings
|
||||
# but those have always been troublesome for cpplint.
|
||||
_ALT_TOKEN_REPLACEMENT_PATTERN = re.compile(
|
||||
r'[ =()](' + ('|'.join(_ALT_TOKEN_REPLACEMENT.keys())) + r')(?=[ (]|$)')
|
||||
|
||||
|
||||
# These constants define types of headers for use with
|
||||
# _IncludeState.CheckNextIncludeOrder().
|
||||
_C_SYS_HEADER = 1
|
||||
@@ -2868,38 +2836,6 @@ def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
|
||||
'Empty loop bodies should use {} or continue')
|
||||
|
||||
|
||||
def CheckAltTokens(filename, clean_lines, linenum, error):
|
||||
"""Check alternative keywords being used in boolean expressions.
|
||||
|
||||
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.
|
||||
"""
|
||||
line = clean_lines.elided[linenum]
|
||||
|
||||
# Avoid preprocessor lines
|
||||
if Match(r'^\s*#', line):
|
||||
return
|
||||
|
||||
# Last ditch effort to avoid multi-line comments. This will not help
|
||||
# if the comment started before the current line or ended after the
|
||||
# current line, but it catches most of the false positives. At least,
|
||||
# it provides a way to workaround this warning for people who use
|
||||
# multi-line comments in preprocessor macros.
|
||||
#
|
||||
# TODO(unknown): remove this once cpplint has better support for
|
||||
# multi-line comments.
|
||||
if line.find('/*') >= 0 or line.find('*/') >= 0:
|
||||
return
|
||||
|
||||
for match in _ALT_TOKEN_REPLACEMENT_PATTERN.finditer(line):
|
||||
error(filename, linenum, 'readability/alt_tokens', 2,
|
||||
'Use operator %s instead of %s' % (
|
||||
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
|
||||
|
||||
|
||||
def GetLineWidth(line):
|
||||
"""Determines the width of the line in column positions.
|
||||
|
||||
@@ -3023,7 +2959,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
|
||||
CheckBraces(filename, clean_lines, linenum, error)
|
||||
CheckEmptyBlockBody(filename, clean_lines, linenum, error)
|
||||
CheckSpacing(filename, clean_lines, linenum, nesting_state, error)
|
||||
CheckAltTokens(filename, clean_lines, linenum, error)
|
||||
|
||||
|
||||
_RE_PATTERN_INCLUDE_NEW_STYLE = re.compile(r'#include +"[^/]+\.h"')
|
||||
|
Reference in New Issue
Block a user