tools: refloat 4 Node.js patches to cpplint.py · nodejs/node@cd2987f (original) (raw)

`@@ -280,6 +280,7 @@

`

280

280

`'build/include',

`

281

281

`'build/include_subdir',

`

282

282

`'build/include_alpha',

`

``

283

`+

'build/include_inline',

`

283

284

`'build/include_order',

`

284

285

`'build/include_what_you_use',

`

285

286

`'build/namespaces_literals',

`

`@@ -294,11 +295,13 @@

`

294

295

`'readability/constructors',

`

295

296

`'readability/fn_size',

`

296

297

`'readability/inheritance',

`

``

298

`+

'readability/pointer_notation',

`

297

299

`'readability/multiline_comment',

`

298

300

`'readability/multiline_string',

`

299

301

`'readability/namespace',

`

300

302

`'readability/nolint',

`

301

303

`'readability/nul',

`

``

304

`+

'readability/null_usage',

`

302

305

`'readability/strings',

`

303

306

`'readability/todo',

`

304

307

`'readability/utf8',

`

622

625

`# Match string that indicates we're working on a Linux Kernel file.

`

623

626

`_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')

`

624

627

``

``

628

`+

_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')

`

``

629

+

``

630

`+

_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'

`

``

631

`+

r'(?<!(sizeof|return))'

`

``

632

`+

r'\s*[a-zA-Z_][0-9a-zA-Z_]*')

`

``

633

+

625

634

`_regexp_compile_cache = {}

`

626

635

``

627

636

`# {str, set(int)}: a map from error categories to sets of linenumbers

`

`@@ -641,7 +650,7 @@

`

641

650

`# Files to exclude from linting. This is set by the --exclude flag.

`

642

651

`_excludes = None

`

643

652

``

644

``

`-

Whether to supress PrintInfo messages

`

``

653

`+

Whether to suppress PrintInfo messages

`

645

654

`_quiet = False

`

646

655

``

647

656

`# The allowed line length of files.

`

`@@ -841,9 +850,9 @@ class _IncludeState(object):

`

841

850

`# needs to move backwards, CheckNextIncludeOrder will raise an error.

`

842

851

`_INITIAL_SECTION = 0

`

843

852

`_MY_H_SECTION = 1

`

844

``

`-

_C_SECTION = 2

`

845

``

`-

_CPP_SECTION = 3

`

846

``

`-

_OTHER_H_SECTION = 4

`

``

853

`+

_OTHER_H_SECTION = 2

`

``

854

`+

_C_SECTION = 3

`

``

855

`+

_CPP_SECTION = 4

`

847

856

``

848

857

`_TYPE_NAMES = {

`

849

858

`_C_SYS_HEADER: 'C system header',

`

`@@ -855,9 +864,9 @@ class _IncludeState(object):

`

855

864

`_SECTION_NAMES = {

`

856

865

`_INITIAL_SECTION: "... nothing. (This can't be an error.)",

`

857

866

`_MY_H_SECTION: 'a header this file implements',

`

``

867

`+

_OTHER_H_SECTION: 'other header',

`

858

868

`_C_SECTION: 'C system header',

`

859

869

`_CPP_SECTION: 'C++ system header',

`

860

``

`-

_OTHER_H_SECTION: 'other header',

`

861

870

` }

`

862

871

``

863

872

`def init(self):

`

`@@ -2253,6 +2262,21 @@ def CheckForBadCharacters(filename, lines, error):

`

2253

2262

`error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')

`

2254

2263

``

2255

2264

``

``

2265

`+

def CheckInlineHeader(filename, include_state, error):

`

``

2266

`+

"""Logs an error if both a header and its inline variant are included."""

`

``

2267

+

``

2268

`+

all_headers = dict(item for sublist in include_state.include_list

`

``

2269

`+

for item in sublist)

`

``

2270

`+

bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()

`

``

2271

`+

if name.endswith('-inl.h'))

`

``

2272

`+

bad_headers &= set(all_headers.keys())

`

``

2273

+

``

2274

`+

for name in bad_headers:

`

``

2275

`+

err = '%s includes both %s and %s-inl.h' % (filename, name, name)

`

``

2276

`+

linenum = all_headers[name]

`

``

2277

`+

error(filename, linenum, 'build/include_inline', 5, err)

`

``

2278

+

``

2279

+

2256

2280

`def CheckForNewlineAtEOF(filename, lines, error):

`

2257

2281

`"""Logs an error if there is no newline char at the end of the file.

`

2258

2282

``

`@@ -4501,6 +4525,49 @@ def CheckAltTokens(filename, clean_lines, linenum, error):

`

4501

4525

`'Use operator %s instead of %s' % (

`

4502

4526

`_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))

`

4503

4527

``

``

4528

`+

def CheckNullTokens(filename, clean_lines, linenum, error):

`

``

4529

`+

"""Check NULL usage.

`

``

4530

+

``

4531

`+

Args:

`

``

4532

`+

filename: The name of the current file.

`

``

4533

`+

clean_lines: A CleansedLines instance containing the file.

`

``

4534

`+

linenum: The number of the line to check.

`

``

4535

`+

error: The function to call with any errors found.

`

``

4536

`+

"""

`

``

4537

`+

line = clean_lines.elided[linenum]

`

``

4538

+

``

4539

`+

Avoid preprocessor lines

`

``

4540

`+

if Match(r'^\s*#', line):

`

``

4541

`+

return

`

``

4542

+

``

4543

`+

if line.find('/') >= 0 or line.find('/') >= 0:

`

``

4544

`+

return

`

``

4545

+

``

4546

`+

for match in _NULL_TOKEN_PATTERN.finditer(line):

`

``

4547

`+

error(filename, linenum, 'readability/null_usage', 2,

`

``

4548

`+

'Use nullptr instead of NULL')

`

``

4549

+

``

4550

`+

def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):

`

``

4551

`+

"""Check for left-leaning pointer placement.

`

``

4552

+

``

4553

`+

Args:

`

``

4554

`+

filename: The name of the current file.

`

``

4555

`+

clean_lines: A CleansedLines instance containing the file.

`

``

4556

`+

linenum: The number of the line to check.

`

``

4557

`+

error: The function to call with any errors found.

`

``

4558

`+

"""

`

``

4559

`+

line = clean_lines.elided[linenum]

`

``

4560

+

``

4561

`+

Avoid preprocessor lines

`

``

4562

`+

if Match(r'^\s*#', line):

`

``

4563

`+

return

`

``

4564

+

``

4565

`+

if '/' in line or '/' in line:

`

``

4566

`+

return

`

``

4567

+

``

4568

`+

for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):

`

``

4569

`+

error(filename, linenum, 'readability/pointer_notation', 2,

`

``

4570

`+

'Use left leaning pointer instead of right leaning')

`

4504

4571

``

4505

4572

`def GetLineWidth(line):

`

4506

4573

`"""Determines the width of the line in column positions.

`

`@@ -4655,6 +4722,8 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,

`

4655

4722

`CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)

`

4656

4723

`CheckCheck(filename, clean_lines, linenum, error)

`

4657

4724

`CheckAltTokens(filename, clean_lines, linenum, error)

`

``

4725

`+

CheckNullTokens(filename, clean_lines, linenum, error)

`

``

4726

`+

CheckLeftLeaningPointer(filename, clean_lines, linenum, error)

`

4658

4727

`classinfo = nesting_state.InnermostClass()

`

4659

4728

`if classinfo:

`

4660

4729

`CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)

`

`@@ -4819,11 +4888,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):

`

4819

4888

`include_state.include_list[-1].append((include, linenum))

`

4820

4889

``

4821

4890

`# We want to ensure that headers appear in the right order:

`

4822

``

`-

1) for foo.cc, foo.h (preferred location)

`

4823

``

`-

2) c system files

`

4824

``

`-

3) cpp system files

`

4825

``

`-

4) for foo.cc, foo.h (deprecated location)

`

4826

``

`-

5) other google headers

`

``

4891

`+

1) for foo.cc, foo.h

`

``

4892

`+

2) other project headers

`

``

4893

`+

3) c system files

`

``

4894

`+

4) cpp system files

`

4827

4895

`#

`

4828

4896

`# We classify each include statement as one of those 5 types

`

4829

4897

`# using a number of techniques. The include_state object keeps

`

`@@ -6197,6 +6265,8 @@ def ProcessFileData(filename, file_extension, lines, error,

`

6197

6265

``

6198

6266

`CheckForNewlineAtEOF(filename, lines, error)

`

6199

6267

``

``

6268

`+

CheckInlineHeader(filename, include_state, error)

`

``

6269

+

6200

6270

`def ProcessConfigOverrides(filename):

`

6201

6271

`""" Loads the configuration files and processes the config overrides.

`

6202

6272

``