Skip to content

Commit 5d1f487

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
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 <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 3a70984 commit 5d1f487

19 files changed

+99
-85
lines changed

pkg/analysis_server/benchmark/integration/input_converter.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'operation.dart';
1919

2020
/// Common input converter superclass for sharing implementation.
2121
abstract class CommonInputConverter extends Converter<String, Operation?> {
22-
static final ERROR_PREFIX = 'Server responded with an error: ';
22+
static const _errorPrefix = 'Server responded with an error: ';
2323
final Logger logger = Logger('InstrumentationInputConverter');
2424
final Set<String> eventsSeen = <String>{};
2525

@@ -172,8 +172,8 @@ abstract class CommonInputConverter extends Converter<String, Operation?> {
172172
var result = exception;
173173
if (exception is UnimplementedError) {
174174
var message = exception.message;
175-
if (message!.startsWith(ERROR_PREFIX)) {
176-
result = json.decode(message.substring(ERROR_PREFIX.length));
175+
if (message!.startsWith(_errorPrefix)) {
176+
result = json.decode(message.substring(_errorPrefix.length));
177177
}
178178
}
179179
processResponseResult(id, result);

pkg/analysis_server/benchmark/integration/instrumentation_input_converter.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import 'package:logging/logging.dart';
1111
import 'input_converter.dart';
1212
import 'operation.dart';
1313

14-
final int COLON = ':'.codeUnitAt(0);
15-
1614
/// [InstrumentationInputConverter] converts an instrumentation stream
1715
/// into a series of operations to be sent to the analysis server.
1816
class InstrumentationInputConverter extends CommonInputConverter {
17+
static final _colon = ':'.codeUnitAt(0);
18+
1919
final Set<String> codesSeen = <String>{};
2020

2121
/// [readBuffer] holds the contents of the file being read from disk
@@ -109,10 +109,10 @@ class InstrumentationInputConverter extends CommonInputConverter {
109109
var sb = StringBuffer();
110110
while (index < line.length) {
111111
var code = line.codeUnitAt(index);
112-
if (code == COLON) {
112+
if (code == _colon) {
113113
// Embedded colons are doubled
114114
var next = index + 1;
115-
if (next < line.length && line.codeUnitAt(next) == COLON) {
115+
if (next < line.length && line.codeUnitAt(next) == _colon) {
116116
sb.write(':');
117117
++index;
118118
} else {

pkg/analysis_server/benchmark/integration/log_file_input_converter.dart

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,31 @@ import 'package:logging/logging.dart';
1010
import 'input_converter.dart';
1111
import 'operation.dart';
1212

13-
const CONNECTED_MSG_FRAGMENT = ' <= {"event":"server.connected"';
14-
const RECEIVED_FRAGMENT = ' <= {';
15-
const SENT_FRAGMENT = ' => {';
16-
final int NINE = '9'.codeUnitAt(0);
17-
final int ZERO = '0'.codeUnitAt(0);
18-
1913
/// [LogFileInputConverter] converts a log file stream
2014
/// into a series of operations to be sent to the analysis server.
2115
class LogFileInputConverter extends CommonInputConverter {
16+
static const _connectedMsgFragment = ' <= {"event":"server.connected"';
17+
static const _receivedFragment = ' <= {';
18+
static const _sentFragment = ' => {';
19+
20+
static final _nine = '9'.codeUnitAt(0);
21+
static final _zero = '0'.codeUnitAt(0);
22+
2223
LogFileInputConverter(super.tmpSrcDirPath, super.srcPathMap);
2324

2425
@override
2526
Operation? convert(String line) {
2627
try {
2728
var timeStampString = _parseTimeStamp(line);
2829
var data = line.substring(timeStampString.length);
29-
if (data.startsWith(RECEIVED_FRAGMENT)) {
30+
if (data.startsWith(_receivedFragment)) {
3031
var jsonData = asMap(json.decode(data.substring(4)));
3132
if (jsonData.containsKey('event')) {
3233
return convertNotification(jsonData);
3334
} else {
3435
return convertResponse(jsonData);
3536
}
36-
} else if (data.startsWith(SENT_FRAGMENT)) {
37+
} else if (data.startsWith(_sentFragment)) {
3738
var jsonData = asMap(json.decode(data.substring(4)));
3839
if (jsonData.containsKey('method')) {
3940
return convertRequest(jsonData);
@@ -56,9 +57,9 @@ class LogFileInputConverter extends CommonInputConverter {
5657
static bool isFormat(String line) {
5758
var timeStampString = _parseTimeStamp(line);
5859
var start = timeStampString.length;
59-
var end = start + CONNECTED_MSG_FRAGMENT.length;
60+
var end = start + _connectedMsgFragment.length;
6061
return (10 < start && end < line.length) &&
61-
line.substring(start, end) == CONNECTED_MSG_FRAGMENT;
62+
line.substring(start, end) == _connectedMsgFragment;
6263
}
6364

6465
/// Parse the given line and return the millisecond timestamp or `null`
@@ -67,7 +68,7 @@ class LogFileInputConverter extends CommonInputConverter {
6768
var index = 0;
6869
while (index < line.length) {
6970
var code = line.codeUnitAt(index);
70-
if (code < ZERO || NINE < code) {
71+
if (code < _zero || _nine < code) {
7172
return line.substring(0, index);
7273
}
7374
++index;

pkg/analysis_server/lib/protocol/protocol.dart

-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ abstract class RequestOrResponse {
291291
///
292292
/// Clients may not extend, implement or mix-in this class.
293293
class Response extends RequestOrResponse {
294-
/// The [Response] instance that is returned when a real [Response] cannot
295-
/// be provided at the moment.
296-
static final Response DELAYED_RESPONSE = Response('DELAYED_RESPONSE');
297-
298294
/// The name of the JSON attribute containing the id of the request for which
299295
/// this is a response.
300296
static const String ID = 'id';

pkg/analysis_server/lib/src/computer/computer_highlights.dart

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Many functions here are mostly camelcase, with an occasional underscore to
6+
// separate phrases.
7+
// ignore_for_file: non_constant_identifier_names
8+
59
import 'dart:math' as math;
610

711
import 'package:_fe_analyzer_shared/src/parser/quote.dart'

pkg/analysis_server/lib/src/protocol_server.dart

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Many functions here are mostly camelcase, with an occasional underscore to
6+
// separate phrases.
7+
// ignore_for_file: non_constant_identifier_names
8+
59
import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
610
import 'package:analysis_server/protocol/protocol_generated.dart';
711
import 'package:analysis_server/src/computer/computer_color.dart';

pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Many functions here are mostly camelcase, with an occasional underscore to
6+
// separate phrases.
7+
// ignore_for_file: non_constant_identifier_names
8+
59
import 'dart:math';
610

711
import 'package:analysis_server/src/protocol_server.dart' hide Element;
@@ -129,7 +133,7 @@ class StatementCompletionKind {
129133

130134
/// The computer for Dart statement completions.
131135
class StatementCompletionProcessor {
132-
static final NO_COMPLETION = StatementCompletion(
136+
static final _noCompletion = StatementCompletion(
133137
DartStatementCompletion.NO_COMPLETION,
134138
SourceChange('', edits: []),
135139
);
@@ -167,13 +171,13 @@ class StatementCompletionProcessor {
167171
Future<StatementCompletion> compute() async {
168172
var node = _selectedNode();
169173
if (node == null) {
170-
return NO_COMPLETION;
174+
return _noCompletion;
171175
}
172176
node = node.thisOrAncestorMatching(
173177
(n) => n is Statement || _isNonStatementDeclaration(n),
174178
);
175179
if (node == null) {
176-
return _complete_simpleEnter() ? completion! : NO_COMPLETION;
180+
return _complete_simpleEnter() ? completion! : _noCompletion;
177181
}
178182
if (node is Block) {
179183
if (node.statements.isNotEmpty) {
@@ -227,7 +231,7 @@ class StatementCompletionProcessor {
227231
if (_complete_simpleEnter()) {
228232
return completion!;
229233
}
230-
return NO_COMPLETION;
234+
return _noCompletion;
231235
}
232236

233237
void _addInsertEdit(int offset, String text) {

pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Many functions here are mostly camelcase, with an occasional underscore to
6+
// separate phrases.
7+
// ignore_for_file: non_constant_identifier_names
8+
59
import 'dart:math' as math;
610

711
import 'package:analysis_server/src/services/correction/fix.dart';

pkg/analysis_server/lib/src/services/correction/levenshtein.dart

+19-19
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,40 @@ int levenshtein(
3535
t = t.toLowerCase();
3636
}
3737

38-
var s_len = s.length;
39-
var t_len = t.length;
38+
var sLength = s.length;
39+
var tLength = t.length;
4040

4141
// if one string is empty,
4242
// the edit distance is necessarily the length of the other
43-
if (s_len == 0) {
44-
return t_len <= threshold ? t_len : LEVENSHTEIN_MAX;
43+
if (sLength == 0) {
44+
return tLength <= threshold ? tLength : LEVENSHTEIN_MAX;
4545
}
46-
if (t_len == 0) {
47-
return s_len <= threshold ? s_len : LEVENSHTEIN_MAX;
46+
if (tLength == 0) {
47+
return sLength <= threshold ? sLength : LEVENSHTEIN_MAX;
4848
}
4949
// the distance can never be less than abs(s_len - t_len)
50-
if ((s_len - t_len).abs() > threshold) {
50+
if ((sLength - tLength).abs() > threshold) {
5151
return LEVENSHTEIN_MAX;
5252
}
5353

5454
// swap the two strings to consume less memory
55-
if (s_len > t_len) {
55+
if (sLength > tLength) {
5656
var tmp = s;
5757
s = t;
5858
t = tmp;
59-
s_len = t_len;
60-
t_len = t.length;
59+
sLength = tLength;
60+
tLength = t.length;
6161
}
6262

6363
// 'previous' cost array, horizontally
64-
var p = List<int>.filled(s_len + 1, 0);
64+
var p = List<int>.filled(sLength + 1, 0);
6565
// cost array, horizontally
66-
var d = List<int>.filled(s_len + 1, 0);
66+
var d = List<int>.filled(sLength + 1, 0);
6767
// placeholder to assist in swapping p and d
6868
List<int> holder;
6969

7070
// fill in starting table values
71-
var boundary = math.min(s_len, threshold) + 1;
71+
var boundary = math.min(sLength, threshold) + 1;
7272
for (var i = 0; i < boundary; i++) {
7373
p[i] = i;
7474
}
@@ -79,14 +79,14 @@ int levenshtein(
7979
_setRange(d, 0, d.length, _MAX_VALUE);
8080

8181
// iterates through t
82-
for (var j = 1; j <= t_len; j++) {
82+
for (var j = 1; j <= tLength; j++) {
8383
// jth character of t
84-
var t_j = t.codeUnitAt(j - 1);
84+
var tAtJ = t.codeUnitAt(j - 1);
8585
d[0] = j;
8686

8787
// compute stripe indices, constrain to array size
8888
var min = math.max(1, j - threshold);
89-
var max = math.min(s_len, j + threshold);
89+
var max = math.min(sLength, j + threshold);
9090

9191
// the stripe may lead off of the table if s and t are of different sizes
9292
if (min > max) {
@@ -100,7 +100,7 @@ int levenshtein(
100100

101101
// iterates through [min, max] in s
102102
for (var i = min; i <= max; i++) {
103-
if (s.codeUnitAt(i - 1) == t_j) {
103+
if (s.codeUnitAt(i - 1) == tAtJ) {
104104
// diagonally left and up
105105
d[i] = p[i - 1];
106106
} else {
@@ -117,8 +117,8 @@ int levenshtein(
117117

118118
// if p[n] is greater than the threshold,
119119
// there's no guarantee on it being the correct distance
120-
if (p[s_len] <= threshold) {
121-
return p[s_len];
120+
if (p[sLength] <= threshold) {
121+
return p[sLength];
122122
}
123123

124124
return LEVENSHTEIN_MAX;

pkg/analysis_server/lib/src/services/correction/name_suggestion.dart

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import 'package:analyzer/dart/element/type.dart';
99
import 'package:analyzer/src/utilities/extensions/string.dart';
1010
import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
1111

12-
final List<String> _KNOWN_METHOD_NAME_PREFIXES = ['get', 'is', 'to'];
13-
1412
/// Returns all variants of names by removing leading words one by one.
1513
List<String> getCamelWordCombinations(String name) {
1614
var result = <String>[];
@@ -215,15 +213,15 @@ String? _getBaseNameFromUnwrappedExpression(Expression expression) {
215213
name = name.substring(0, name.length - 1);
216214
}
217215
}
218-
// strip known prefixes
216+
// Strip known prefixes.
219217
if (name != null) {
220-
for (var i = 0; i < _KNOWN_METHOD_NAME_PREFIXES.length; i++) {
221-
var curr = _KNOWN_METHOD_NAME_PREFIXES[i];
222-
if (name.startsWith(curr)) {
223-
if (name == curr) {
218+
const knownMethodNamePrefixes = ['get', 'is', 'to'];
219+
for (var knownPrefix in knownMethodNamePrefixes) {
220+
if (name.startsWith(knownPrefix)) {
221+
if (name == knownPrefix) {
224222
return null;
225-
} else if (isUpperCase(name.codeUnitAt(curr.length))) {
226-
return name.substring(curr.length);
223+
} else if (isUpperCase(name.codeUnitAt(knownPrefix.length))) {
224+
return name.substring(knownPrefix.length);
227225
}
228226
}
229227
}

pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring_manager.dart

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Many variables here are mostly camelcase, with an occasional underscore to
6+
// separate phrases.
7+
// ignore_for_file: non_constant_identifier_names
8+
59
import 'dart:async';
610

711
import 'package:analysis_server/src/collections.dart';

pkg/analysis_server/lib/src/utilities/stream.dart

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,22 @@ class MoreTypedStreamController<T, ListenData, PauseData> {
2828
if (pauseData != null) {
2929
throw StateError('Already paused');
3030
}
31-
var local_onPause = onPause;
32-
if (local_onPause != null) {
33-
pauseData = local_onPause(listenData as ListenData);
31+
if (onPause != null) {
32+
pauseData = onPause(listenData as ListenData);
3433
}
3534
},
3635
onResume: () {
37-
var local_onResume = onResume;
38-
if (local_onResume != null) {
39-
var local_pauseData = pauseData as PauseData;
36+
if (onResume != null) {
37+
var currentPauseData = pauseData as PauseData;
4038
pauseData = null;
41-
local_onResume(listenData as ListenData, local_pauseData);
39+
onResume(listenData as ListenData, currentPauseData);
4240
}
4341
},
4442
onCancel: () {
45-
var local_onCancel = onCancel;
46-
if (local_onCancel != null) {
47-
var local_listenData = listenData as ListenData;
43+
if (onCancel != null) {
44+
var currentListenData = listenData as ListenData;
4845
listenData = null;
49-
local_onCancel(local_listenData);
46+
onCancel(currentListenData);
5047
}
5148
},
5249
sync: sync,

pkg/analysis_server/lib/src/utilities/strings.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ int findCommonPrefix(String a, String b) {
100100

101101
/// Returns the number of characters common to the end of [a] and [b].
102102
int findCommonSuffix(String a, String b) {
103-
var a_length = a.length;
104-
var b_length = b.length;
105-
var n = min(a_length, b_length);
103+
var aLength = a.length;
104+
var bLength = b.length;
105+
var n = min(aLength, bLength);
106106
for (var i = 1; i <= n; i++) {
107-
if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) {
107+
if (a.codeUnitAt(aLength - i) != b.codeUnitAt(bLength - i)) {
108108
return i - 1;
109109
}
110110
}

pkg/analysis_server/test/analysis_options.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ analyzer:
77
# We have some long test class names which include one or more underscores
88
# to improve readability.
99
camel_case_types: ignore
10-
10+
# There are just over 100 violations of this, which can likely be ignored
11+
# on a case-by-case or file-by-file basis.
12+
non_constant_identifier_names: ignore

0 commit comments

Comments
 (0)