Skip to content

Commit 512c135

Browse files
committed
Don't start debug mode by default
1 parent 0953792 commit 512c135

File tree

9 files changed

+85
-27
lines changed

9 files changed

+85
-27
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- [Using our custom lint package in an application](#using-our-custom-lint-package-in-an-application)
2626
- [Enabling/disabling and configuring lints](#enablingdisabling-and-configuring-lints)
2727
- [Obtaining the list of lints in the CI](#obtaining-the-list-of-lints-in-the-ci)
28-
- [Using the Dart debugger](#using-the-dart-debugger)
28+
- [Using the Dart debugger and enabling hot-reload](#using-the-dart-debugger-and-enabling-hot-reload)
2929
- [Testing your plugins](#testing-your-plugins)
3030
- [Testing lints](#testing-lints)
3131
- [Testing quick fixes and assists](#testing-quick-fixes-and-assists)
@@ -238,9 +238,26 @@ $ dart run custom_lint
238238

239239
If you are working on a Flutter project, run `flutter pub run custom_lint` instead.
240240

241-
### Using the Dart debugger
241+
### Using the Dart debugger and enabling hot-reload
242242

243-
To debug plugins in custom_lint, you need to connect to plugins using "attach"
243+
By default, custom_lint does enable hot-reload or give you the necessary
244+
information to start the debugger. This is because most users don't need those,
245+
and only lint authors do.
246+
247+
If you wish to debug lints, you'll have to update your `analysis_options.yaml` as followed:
248+
249+
```yaml
250+
analyzer:
251+
plugins:
252+
- custom_lint
253+
254+
custom_lint:
255+
debug: true
256+
# Optional, will cause custom_lint to log its internal debug information
257+
verbose: true
258+
```
259+
260+
Then, to debug plugins in custom_lint, you need to connect to plugins using "attach"
244261
mode in your IDE (`cmd+shift+p` + `Debug: attach to Dart process` in VSCode).
245262

246263
When using this command, you will need a VM service URI provided by custom_lint.

packages/custom_lint/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased patch
22

33
- Fixed Unimplemented error when running `pub get`.
4+
- Hot-reload and debug mode is now disabled by default.
45

56
## 0.6.2 - 2024-02-19
67

packages/custom_lint/lib/src/analyzer_plugin_starter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void start(Iterable<String> _, SendPort sendPort) {
2020
// enable watch mode. There's no way to detect this, but this only matters
2121
// in the CI. So we disable watch mode if we detect that we're in CI.
2222
// TODO enable hot-restart only if running plugin from source (excluding pub cache)
23-
watchMode: !isInCI,
23+
watchMode: isInCI ? false : null,
2424
delegate: AnalyzerPluginCustomLintDelegate(),
2525
workingDirectory: Directory.current,
2626
);

packages/custom_lint/lib/src/v2/custom_lint_analyzer_plugin.dart

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import 'dart:async';
22
import 'dart:io';
33
import 'dart:isolate';
44

5+
import 'package:analyzer/file_system/physical_file_system.dart';
56
import 'package:analyzer_plugin/protocol/protocol.dart';
67
import 'package:analyzer_plugin/protocol/protocol_constants.dart';
78
import 'package:analyzer_plugin/protocol/protocol_generated.dart';
89
// ignore: implementation_imports
910
import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'
1011
show ResponseResult;
1112
import 'package:async/async.dart';
13+
import 'package:custom_lint_core/custom_lint_core.dart';
14+
import 'package:package_config/package_config.dart';
15+
import 'package:path/path.dart' as p;
1216
import 'package:pub_semver/pub_semver.dart';
1317
import 'package:rxdart/rxdart.dart';
1418
import 'package:uuid/uuid.dart';
@@ -37,7 +41,7 @@ class CustomLintServer {
3741
/// errors and prints continue to be captured.
3842
static Future<CustomLintServer> start({
3943
required SendPort sendPort,
40-
required bool watchMode,
44+
required bool? watchMode,
4145
required bool includeBuiltInLints,
4246
required bool fix,
4347
required CustomLintDelegate delegate,
@@ -97,7 +101,7 @@ class CustomLintServer {
97101
late final AnalyzerPluginClientChannel _analyzerPluginClientChannel;
98102

99103
/// Whether plugins should be started in watch mode
100-
final bool watchMode;
104+
final bool? watchMode;
101105

102106
/// If enabled, attempt to fix all issues found before reporting them.
103107
/// Can only be enabled in the CLI.
@@ -368,7 +372,26 @@ class CustomLintServer {
368372
_clientChannelEventsSubscription = clientChannel.events.listen(
369373
_handleEvent,
370374
);
371-
await clientChannel.init();
375+
376+
final configs = await Future.wait(
377+
parameters.roots.map(
378+
(e) async {
379+
final packageConfig = await findPackageConfig(Directory(e.root));
380+
if (packageConfig == null) return null;
381+
382+
return CustomLintConfigs.parse(
383+
PhysicalResourceProvider.INSTANCE.getFile(
384+
p.join(e.root, 'analysis_options.yaml'),
385+
),
386+
packageConfig,
387+
);
388+
},
389+
),
390+
);
391+
392+
await clientChannel.init(
393+
debug: configs.any((e) => e != null && e.debug),
394+
);
372395
}
373396

374397
Future<void> _handleEvent(CustomLintEvent event) => _runner.run(() async {

packages/custom_lint/lib/src/v2/server_to_client_channel.dart

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,13 @@ class SocketCustomLintServerToClientChannel {
106106
}
107107

108108
/// Initializes and waits for the client to start
109-
Future<void> init() async {
110-
_processFuture = _startProcess();
109+
Future<void> init({required bool debug}) async {
110+
_processFuture = _startProcess(debug: debug);
111111
final process = await _processFuture;
112112
// No process started, likely because no plugin were detected. We can stop here.
113113
if (process == null) return;
114114

115-
var out = process.stdout.map(utf8.decode);
116-
// Let's not log the VM service prints unless in watch mode
117-
if (!_server.watchMode) {
118-
out = out.skipWhile(
119-
(element) =>
120-
element.startsWith('The Dart VM service is listening on') ||
121-
element.startsWith(
122-
'The Dart DevTools debugger and profiler is available at:',
123-
),
124-
);
125-
}
115+
final out = process.stdout.map(utf8.decode);
126116

127117
out.listen((event) => _server.handlePrint(event, isClientMessage: true));
128118
process.stderr
@@ -151,7 +141,9 @@ class SocketCustomLintServerToClientChannel {
151141
/// without setting up the connection.
152142
///
153143
/// Will throw if the process fails to start.
154-
Future<Process?> _startProcess() async {
144+
Future<Process?> _startProcess({
145+
required bool debug,
146+
}) async {
155147
final tempDir = _tempDirectory =
156148
Directory.systemTemp.createTempSync('custom_lint_client');
157149

@@ -163,7 +155,7 @@ class SocketCustomLintServerToClientChannel {
163155
final process = await Process.start(
164156
Platform.resolvedExecutable,
165157
[
166-
if (_server.watchMode) '--enable-vm-service=0',
158+
if (_server.watchMode ?? debug) '--enable-vm-service=0',
167159
join('lib', 'custom_lint_client.dart'),
168160
_serverSocket.address.host,
169161
_serverSocket.port.toString(),

packages/custom_lint/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies:
1515
ci: ^0.1.0
1616
cli_util: ^0.4.0
1717
collection: ^1.16.0
18+
custom_lint_core: 0.6.2
1819
freezed_annotation: ^2.2.0
1920
json_annotation: ^4.7.0
2021
meta: ^1.7.0

packages/custom_lint/tools/analyzer_plugin/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ environment:
88

99
dependencies:
1010
custom_lint: 0.6.2
11-
1211
# TODO: If you want to contribute to custom_lint, add a pubspec_overrides.yaml file
1312
# in this folder, containing the following:
1413
# dependency_overrides:

packages/custom_lint_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased patch
2+
3+
- Parses `debug`/`config` flags
4+
15
## 0.6.2 - 2024-02-19
26

37
- Fix null exception when using `TypeChecker.isSuperTypeOf` (thanks to @charlescyt)

packages/custom_lint_core/lib/src/configs.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ class CustomLintConfigs {
1414
@internal
1515
const CustomLintConfigs({
1616
required this.enableAllLintRules,
17+
required this.verbose,
18+
required this.debug,
1719
required this.rules,
1820
});
1921

2022
/// Decode a [CustomLintConfigs] from a file.
21-
@internal
2223
factory CustomLintConfigs.parse(
2324
File? analysisOptionsFile,
2425
PackageConfig packageConfig,
@@ -67,9 +68,15 @@ class CustomLintConfigs {
6768

6869
final rules = <String, LintOptions>{...includedOptions.rules};
6970
final enableAllLintRulesYaml = customLint['enable_all_lint_rules'];
70-
final enableAllLintRules = enableAllLintRulesYaml is bool?
71-
? enableAllLintRulesYaml ?? includedOptions.enableAllLintRules
72-
: null;
71+
final enableAllLintRules = enableAllLintRulesYaml is bool
72+
? enableAllLintRulesYaml
73+
: includedOptions.enableAllLintRules;
74+
75+
final debugYaml = customLint['debug'];
76+
final debug = debugYaml is bool ? debugYaml : includedOptions.debug;
77+
78+
final verboseYaml = customLint['verbose'];
79+
final verbose = verboseYaml is bool ? verboseYaml : includedOptions.verbose;
7380

7481
final rulesYaml = customLint['rules'] as Object?;
7582

@@ -103,6 +110,8 @@ class CustomLintConfigs {
103110

104111
return CustomLintConfigs(
105112
enableAllLintRules: enableAllLintRules,
113+
verbose: verbose,
114+
debug: debug,
106115
rules: UnmodifiableMapView(rules),
107116
);
108117
}
@@ -111,6 +120,8 @@ class CustomLintConfigs {
111120
@internal
112121
static const empty = CustomLintConfigs(
113122
enableAllLintRules: null,
123+
verbose: false,
124+
debug: false,
114125
rules: {},
115126
);
116127

@@ -130,15 +141,25 @@ class CustomLintConfigs {
130141
/// along with extra per-lint configuration.
131142
final Map<String, LintOptions> rules;
132143

144+
/// Whether to enable verbose logging.
145+
final bool verbose;
146+
147+
/// Whether enable hot-reload and log the VM-service URI.
148+
final bool debug;
149+
133150
@override
134151
bool operator ==(Object other) =>
135152
other is CustomLintConfigs &&
136153
other.enableAllLintRules == enableAllLintRules &&
154+
other.verbose == verbose &&
155+
other.debug == debug &&
137156
const MapEquality<String, LintOptions>().equals(other.rules, rules);
138157

139158
@override
140159
int get hashCode => Object.hash(
141160
enableAllLintRules,
161+
verbose,
162+
debug,
142163
const MapEquality<String, LintOptions>().hash(rules),
143164
);
144165
}

0 commit comments

Comments
 (0)