DAS: Fix many non_constant_identifier_names violations

This lint rule is a core lint rule; we have suppressed it only for
pre-existing code reasons.

There are a few individual files which simply have a consistent pattern
of including underscores in some names, so I add inline ignores there.

Change-Id: I89e6010203868fc10fda12b15353de41881d9b15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416900
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Sam Rawlins
2025-03-20 09:00:06 -07:00
committed by Commit Queue
parent 3a709844b2
commit 5d1f4876ee
19 changed files with 99 additions and 85 deletions
@@ -19,7 +19,7 @@ import 'operation.dart';
/// Common input converter superclass for sharing implementation.
abstract class CommonInputConverter extends Converter<String, Operation?> {
static final ERROR_PREFIX = 'Server responded with an error: ';
static const _errorPrefix = 'Server responded with an error: ';
final Logger logger = Logger('InstrumentationInputConverter');
final Set<String> eventsSeen = <String>{};
@@ -172,8 +172,8 @@ abstract class CommonInputConverter extends Converter<String, Operation?> {
var result = exception;
if (exception is UnimplementedError) {
var message = exception.message;
if (message!.startsWith(ERROR_PREFIX)) {
result = json.decode(message.substring(ERROR_PREFIX.length));
if (message!.startsWith(_errorPrefix)) {
result = json.decode(message.substring(_errorPrefix.length));
}
}
processResponseResult(id, result);
@@ -11,11 +11,11 @@ import 'package:logging/logging.dart';
import 'input_converter.dart';
import 'operation.dart';
final int COLON = ':'.codeUnitAt(0);
/// [InstrumentationInputConverter] converts an instrumentation stream
/// into a series of operations to be sent to the analysis server.
class InstrumentationInputConverter extends CommonInputConverter {
static final _colon = ':'.codeUnitAt(0);
final Set<String> codesSeen = <String>{};
/// [readBuffer] holds the contents of the file being read from disk
@@ -109,10 +109,10 @@ class InstrumentationInputConverter extends CommonInputConverter {
var sb = StringBuffer();
while (index < line.length) {
var code = line.codeUnitAt(index);
if (code == COLON) {
if (code == _colon) {
// Embedded colons are doubled
var next = index + 1;
if (next < line.length && line.codeUnitAt(next) == COLON) {
if (next < line.length && line.codeUnitAt(next) == _colon) {
sb.write(':');
++index;
} else {
@@ -10,15 +10,16 @@ import 'package:logging/logging.dart';
import 'input_converter.dart';
import 'operation.dart';
const CONNECTED_MSG_FRAGMENT = ' <= {"event":"server.connected"';
const RECEIVED_FRAGMENT = ' <= {';
const SENT_FRAGMENT = ' => {';
final int NINE = '9'.codeUnitAt(0);
final int ZERO = '0'.codeUnitAt(0);
/// [LogFileInputConverter] converts a log file stream
/// into a series of operations to be sent to the analysis server.
class LogFileInputConverter extends CommonInputConverter {
static const _connectedMsgFragment = ' <= {"event":"server.connected"';
static const _receivedFragment = ' <= {';
static const _sentFragment = ' => {';
static final _nine = '9'.codeUnitAt(0);
static final _zero = '0'.codeUnitAt(0);
LogFileInputConverter(super.tmpSrcDirPath, super.srcPathMap);
@override
@@ -26,14 +27,14 @@ class LogFileInputConverter extends CommonInputConverter {
try {
var timeStampString = _parseTimeStamp(line);
var data = line.substring(timeStampString.length);
if (data.startsWith(RECEIVED_FRAGMENT)) {
if (data.startsWith(_receivedFragment)) {
var jsonData = asMap(json.decode(data.substring(4)));
if (jsonData.containsKey('event')) {
return convertNotification(jsonData);
} else {
return convertResponse(jsonData);
}
} else if (data.startsWith(SENT_FRAGMENT)) {
} else if (data.startsWith(_sentFragment)) {
var jsonData = asMap(json.decode(data.substring(4)));
if (jsonData.containsKey('method')) {
return convertRequest(jsonData);
@@ -56,9 +57,9 @@ class LogFileInputConverter extends CommonInputConverter {
static bool isFormat(String line) {
var timeStampString = _parseTimeStamp(line);
var start = timeStampString.length;
var end = start + CONNECTED_MSG_FRAGMENT.length;
var end = start + _connectedMsgFragment.length;
return (10 < start && end < line.length) &&
line.substring(start, end) == CONNECTED_MSG_FRAGMENT;
line.substring(start, end) == _connectedMsgFragment;
}
/// Parse the given line and return the millisecond timestamp or `null`
@@ -67,7 +68,7 @@ class LogFileInputConverter extends CommonInputConverter {
var index = 0;
while (index < line.length) {
var code = line.codeUnitAt(index);
if (code < ZERO || NINE < code) {
if (code < _zero || _nine < code) {
return line.substring(0, index);
}
++index;
@@ -291,10 +291,6 @@ abstract class RequestOrResponse {
///
/// Clients may not extend, implement or mix-in this class.
class Response extends RequestOrResponse {
/// The [Response] instance that is returned when a real [Response] cannot
/// be provided at the moment.
static final Response DELAYED_RESPONSE = Response('DELAYED_RESPONSE');
/// The name of the JSON attribute containing the id of the request for which
/// this is a response.
static const String ID = 'id';
@@ -2,6 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Many functions here are mostly camelcase, with an occasional underscore to
// separate phrases.
// ignore_for_file: non_constant_identifier_names
import 'dart:math' as math;
import 'package:_fe_analyzer_shared/src/parser/quote.dart'
@@ -2,6 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Many functions here are mostly camelcase, with an occasional underscore to
// separate phrases.
// ignore_for_file: non_constant_identifier_names
import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/computer/computer_color.dart';
@@ -2,6 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Many functions here are mostly camelcase, with an occasional underscore to
// separate phrases.
// ignore_for_file: non_constant_identifier_names
import 'dart:math';
import 'package:analysis_server/src/protocol_server.dart' hide Element;
@@ -129,7 +133,7 @@ class StatementCompletionKind {
/// The computer for Dart statement completions.
class StatementCompletionProcessor {
static final NO_COMPLETION = StatementCompletion(
static final _noCompletion = StatementCompletion(
DartStatementCompletion.NO_COMPLETION,
SourceChange('', edits: []),
);
@@ -167,13 +171,13 @@ class StatementCompletionProcessor {
Future<StatementCompletion> compute() async {
var node = _selectedNode();
if (node == null) {
return NO_COMPLETION;
return _noCompletion;
}
node = node.thisOrAncestorMatching(
(n) => n is Statement || _isNonStatementDeclaration(n),
);
if (node == null) {
return _complete_simpleEnter() ? completion! : NO_COMPLETION;
return _complete_simpleEnter() ? completion! : _noCompletion;
}
if (node is Block) {
if (node.statements.isNotEmpty) {
@@ -227,7 +231,7 @@ class StatementCompletionProcessor {
if (_complete_simpleEnter()) {
return completion!;
}
return NO_COMPLETION;
return _noCompletion;
}
void _addInsertEdit(int offset, String text) {
@@ -2,6 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Many functions here are mostly camelcase, with an occasional underscore to
// separate phrases.
// ignore_for_file: non_constant_identifier_names
import 'dart:math' as math;
import 'package:analysis_server/src/services/correction/fix.dart';
@@ -35,40 +35,40 @@ int levenshtein(
t = t.toLowerCase();
}
var s_len = s.length;
var t_len = t.length;
var sLength = s.length;
var tLength = t.length;
// if one string is empty,
// the edit distance is necessarily the length of the other
if (s_len == 0) {
return t_len <= threshold ? t_len : LEVENSHTEIN_MAX;
if (sLength == 0) {
return tLength <= threshold ? tLength : LEVENSHTEIN_MAX;
}
if (t_len == 0) {
return s_len <= threshold ? s_len : LEVENSHTEIN_MAX;
if (tLength == 0) {
return sLength <= threshold ? sLength : LEVENSHTEIN_MAX;
}
// the distance can never be less than abs(s_len - t_len)
if ((s_len - t_len).abs() > threshold) {
if ((sLength - tLength).abs() > threshold) {
return LEVENSHTEIN_MAX;
}
// swap the two strings to consume less memory
if (s_len > t_len) {
if (sLength > tLength) {
var tmp = s;
s = t;
t = tmp;
s_len = t_len;
t_len = t.length;
sLength = tLength;
tLength = t.length;
}
// 'previous' cost array, horizontally
var p = List<int>.filled(s_len + 1, 0);
var p = List<int>.filled(sLength + 1, 0);
// cost array, horizontally
var d = List<int>.filled(s_len + 1, 0);
var d = List<int>.filled(sLength + 1, 0);
// placeholder to assist in swapping p and d
List<int> holder;
// fill in starting table values
var boundary = math.min(s_len, threshold) + 1;
var boundary = math.min(sLength, threshold) + 1;
for (var i = 0; i < boundary; i++) {
p[i] = i;
}
@@ -79,14 +79,14 @@ int levenshtein(
_setRange(d, 0, d.length, _MAX_VALUE);
// iterates through t
for (var j = 1; j <= t_len; j++) {
for (var j = 1; j <= tLength; j++) {
// jth character of t
var t_j = t.codeUnitAt(j - 1);
var tAtJ = t.codeUnitAt(j - 1);
d[0] = j;
// compute stripe indices, constrain to array size
var min = math.max(1, j - threshold);
var max = math.min(s_len, j + threshold);
var max = math.min(sLength, j + threshold);
// the stripe may lead off of the table if s and t are of different sizes
if (min > max) {
@@ -100,7 +100,7 @@ int levenshtein(
// iterates through [min, max] in s
for (var i = min; i <= max; i++) {
if (s.codeUnitAt(i - 1) == t_j) {
if (s.codeUnitAt(i - 1) == tAtJ) {
// diagonally left and up
d[i] = p[i - 1];
} else {
@@ -117,8 +117,8 @@ int levenshtein(
// if p[n] is greater than the threshold,
// there's no guarantee on it being the correct distance
if (p[s_len] <= threshold) {
return p[s_len];
if (p[sLength] <= threshold) {
return p[sLength];
}
return LEVENSHTEIN_MAX;
@@ -9,8 +9,6 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/utilities/extensions/string.dart';
import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
final List<String> _KNOWN_METHOD_NAME_PREFIXES = ['get', 'is', 'to'];
/// Returns all variants of names by removing leading words one by one.
List<String> getCamelWordCombinations(String name) {
var result = <String>[];
@@ -215,15 +213,15 @@ String? _getBaseNameFromUnwrappedExpression(Expression expression) {
name = name.substring(0, name.length - 1);
}
}
// strip known prefixes
// Strip known prefixes.
if (name != null) {
for (var i = 0; i < _KNOWN_METHOD_NAME_PREFIXES.length; i++) {
var curr = _KNOWN_METHOD_NAME_PREFIXES[i];
if (name.startsWith(curr)) {
if (name == curr) {
const knownMethodNamePrefixes = ['get', 'is', 'to'];
for (var knownPrefix in knownMethodNamePrefixes) {
if (name.startsWith(knownPrefix)) {
if (name == knownPrefix) {
return null;
} else if (isUpperCase(name.codeUnitAt(curr.length))) {
return name.substring(curr.length);
} else if (isUpperCase(name.codeUnitAt(knownPrefix.length))) {
return name.substring(knownPrefix.length);
}
}
}
@@ -2,6 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Many variables here are mostly camelcase, with an occasional underscore to
// separate phrases.
// ignore_for_file: non_constant_identifier_names
import 'dart:async';
import 'package:analysis_server/src/collections.dart';
@@ -28,25 +28,22 @@ class MoreTypedStreamController<T, ListenData, PauseData> {
if (pauseData != null) {
throw StateError('Already paused');
}
var local_onPause = onPause;
if (local_onPause != null) {
pauseData = local_onPause(listenData as ListenData);
if (onPause != null) {
pauseData = onPause(listenData as ListenData);
}
},
onResume: () {
var local_onResume = onResume;
if (local_onResume != null) {
var local_pauseData = pauseData as PauseData;
if (onResume != null) {
var currentPauseData = pauseData as PauseData;
pauseData = null;
local_onResume(listenData as ListenData, local_pauseData);
onResume(listenData as ListenData, currentPauseData);
}
},
onCancel: () {
var local_onCancel = onCancel;
if (local_onCancel != null) {
var local_listenData = listenData as ListenData;
if (onCancel != null) {
var currentListenData = listenData as ListenData;
listenData = null;
local_onCancel(local_listenData);
onCancel(currentListenData);
}
},
sync: sync,
@@ -100,11 +100,11 @@ int findCommonPrefix(String a, String b) {
/// Returns the number of characters common to the end of [a] and [b].
int findCommonSuffix(String a, String b) {
var a_length = a.length;
var b_length = b.length;
var n = min(a_length, b_length);
var aLength = a.length;
var bLength = b.length;
var n = min(aLength, bLength);
for (var i = 1; i <= n; i++) {
if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) {
if (a.codeUnitAt(aLength - i) != b.codeUnitAt(bLength - i)) {
return i - 1;
}
}
@@ -7,4 +7,6 @@ analyzer:
# We have some long test class names which include one or more underscores
# to improve readability.
camel_case_types: ignore
# There are just over 100 violations of this, which can likely be ignored
# on a case-by-case or file-by-file basis.
non_constant_identifier_names: ignore
@@ -71,7 +71,7 @@ final _homeDir =
? Platform.environment['LOCALAPPDATA']!
: Platform.environment['HOME']!;
final _package_config = path.join('.dart_tool', 'package_config.json');
final _packageConfig = path.join('.dart_tool', 'package_config.json');
Future<CloneResult> _clone(String repo) async {
var name = _trimName(
@@ -106,7 +106,7 @@ Future<ProcessResult> _runPub(String dir) async =>
Future<void> _runPubGet(FileSystemEntity dir) async {
if (_hasPubspec(dir)) {
var packageFile = path.join(dir.path, _package_config);
var packageFile = path.join(dir.path, _packageConfig);
if (!File(packageFile).existsSync() || forcePubUpdate) {
var relativeDirPath = path.relative(dir.path, from: _appDir);
print('Getting pub dependencies for "$relativeDirPath"...');
@@ -215,10 +215,10 @@ class DistributionComputer {
}
/// A computer for the mean reciprocal rank. The MRR as well as the MRR only
/// if the item was in the top 5 in the list see [MAX_RANK], is computed.
/// if the item was in the top 5 in the list see [_maxRank], is computed.
/// https://en.wikipedia.org/wiki/Mean_reciprocal_rank.
class MeanReciprocalRankComputer {
static final int MAX_RANK = 5;
static const int _maxRank = 5;
final String name;
double _sum = 0;
double _sum_5 = 0;
@@ -252,7 +252,7 @@ class MeanReciprocalRankComputer {
void addRank(int rank) {
if (rank != 0) {
_sum += 1 / rank;
if (rank <= MAX_RANK) {
if (rank <= _maxRank) {
_sum_5 += 1 / rank;
}
}
@@ -251,8 +251,8 @@ bool _isSimpleType(TypeBase type) {
bool _isSpecType(TypeBase type) {
type = resolveTypeAlias(type);
return type is TypeReference &&
type != TypeReference.LspObject &&
type != TypeReference.LspAny &&
type != TypeReference.lspObject &&
type != TypeReference.lspAny &&
(_interfaces.containsKey(type.name) ||
(_namespaces.containsKey(type.name)));
}
@@ -184,12 +184,12 @@ List<LspEntity> getCustomClasses() {
var customTypes = <LspEntity>[
TypeAlias(
name: 'LSPAny',
baseType: TypeReference.LspAny,
baseType: TypeReference.lspAny,
renameReferences: false,
),
TypeAlias(
name: 'LSPObject',
baseType: TypeReference.LspObject,
baseType: TypeReference.lspObject,
renameReferences: false,
),
// The DocumentFilter more complex in v3.17's meta_model (to allow
@@ -443,7 +443,7 @@ List<LspEntity> getCustomClasses() {
),
Field(
name: 'value',
type: TypeReference.LspAny,
type: TypeReference.lspAny,
allowsNull: false,
allowsUndefined: true,
comment:
@@ -466,7 +466,7 @@ List<LspEntity> getCustomClasses() {
),
Field(
name: 'defaultValue',
type: TypeReference.LspAny,
type: TypeReference.lspAny,
allowsNull: false,
allowsUndefined: true,
comment:
@@ -536,7 +536,7 @@ List<LspEntity> getCustomClasses() {
field('name', type: 'string'),
Field(
name: 'newValue',
type: TypeReference.LspAny,
type: TypeReference.lspAny,
allowsNull: true,
allowsUndefined: false,
),
@@ -574,7 +574,7 @@ List<LspEntity> getCustomClasses() {
),
AbstractGetter(
name: 'defaultValue',
type: TypeReference.LspAny,
type: TypeReference.lspAny,
comment:
'An optional default value for the parameter. The type of '
'this value may vary between parameter kinds but must always be '
@@ -262,10 +262,10 @@ class TypeReference extends TypeBase {
static final TypeBase int = TypeReference('int');
/// Any object (but not null).
static final TypeBase LspObject = TypeReference('Object');
static final TypeBase lspObject = TypeReference('Object');
/// Any object (or null/undefined).
static final TypeBase LspAny = NullableType(TypeReference.LspObject);
static final TypeBase lspAny = NullableType(TypeReference.lspObject);
final String name;
final List<TypeBase> typeArgs;