tools: add C++ lint rule to avoid using String::Utf8Value

We should be using our own helpers for this instead.

PR-URL: https://github.com/nodejs/node/pull/60244
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
This commit is contained in:
Anna Henningsen 2025-10-13 15:44:30 +02:00 committed by Node.js GitHub Bot
parent 39447be4e4
commit e6d94ef106

22
tools/cpplint.py vendored
View File

@ -6489,6 +6489,26 @@ def CheckLocalVectorUsage(filename, lines, error):
'Do not use std::vector<v8::Local<T>>. ' 'Do not use std::vector<v8::Local<T>>. '
'Use v8::LocalVector<T> instead.') 'Use v8::LocalVector<T> instead.')
def CheckStringValueUsage(filename, lines, error):
"""Logs an error if v8's String::Value/Utf8Value are used.
Args:
filename: The name of the current file.
lines: An array of strings, each representing a line of the file.
error: The function to call with any errors found.
"""
if filename.startswith('test/') or filename.startswith('test\\'):
return # Skip test files, where Node.js headers may not be available
for linenum, line in enumerate(lines):
if Search(r'\bString::Utf8Value\b', line):
error(filename, linenum, 'runtime/v8_string_value', 5,
'Do not use v8::String::Utf8Value. '
'Use node::Utf8Value instead.')
if Search(r'\bString::Value\b', line):
error(filename, linenum, 'runtime/v8_string_value', 5,
'Do not use v8::String::Value. '
'Use node::TwoByteValue instead.')
def ProcessLine(filename, file_extension, clean_lines, line, def ProcessLine(filename, file_extension, clean_lines, line,
include_state, function_state, nesting_state, error, include_state, function_state, nesting_state, error,
extra_check_functions=None): extra_check_functions=None):
@ -6660,6 +6680,8 @@ def ProcessFileData(filename, file_extension, lines, error,
CheckLocalVectorUsage(filename, lines, error) CheckLocalVectorUsage(filename, lines, error)
CheckStringValueUsage(filename, lines, error)
def ProcessConfigOverrides(filename): def ProcessConfigOverrides(filename):
""" Loads the configuration files and processes the config overrides. """ Loads the configuration files and processes the config overrides.