Skip to content

Commit e3c1e1e

Browse files
solid-illiaaihistovIllia Aihistov
andauthored
Updated documentation and dependency updates (#334)
* feat: auto-inject pubspec version into docs * docs: update plugin configuration syntax and README examples for linting rules * chore: update dependencies * fix: correct spelling of loses in Future.wait lint reason * fix: resolve project root using Platform.script --------- Co-authored-by: Illia Aihistov <illia.aihistov-us@solid.software>
1 parent a6d4ae1 commit e3c1e1e

5 files changed

Lines changed: 81 additions & 64 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,39 @@ Enable the plugin and include `solid_lints` in your project's top-level `analysi
2525
include: package:solid_lints/analysis_options.yaml
2626
2727
plugins:
28-
solid_lints:
28+
solid_lints: <INSERT LATEST VERSION>
2929
```
3030

3131
Also, you can use a specialized rule set designed for Dart tests.
3232
Add an `analysis_options.yaml` file under the `test/` directory, and include the ruleset:
3333

3434
```yaml
3535
include: package:solid_lints/analysis_options_test.yaml
36+
37+
plugins:
38+
solid_lints: <INSERT LATEST VERSION>
3639
```
3740

3841
Then you can see suggestions in your IDE or you can run checks manually:
3942

4043
```bash
41-
dart analyze;
44+
dart analyze
4245
```
4346

4447
# Configuration
4548

46-
You can customize individual rule settings in your `analysis_options.yaml`.
47-
48-
### Option 1: Inside the `plugins` block (Recommended)
49+
You can customize individual rule settings in your `analysis_options.yaml`:
4950

5051
```yaml
5152
plugins:
5253
solid_lints:
54+
version: <INSERT LATEST VERSION>
5355
diagnostics:
5456
cyclomatic_complexity:
5557
max_complexity: 10
5658
avoid_non_null_assertion: true
5759
```
5860

59-
### Option 2: Separate top-level `solid_lints` block
60-
61-
```yaml
62-
plugins:
63-
solid_lints:
64-
65-
solid_lints:
66-
diagnostics:
67-
cyclomatic_complexity:
68-
max_complexity: 10
69-
avoid_non_null_assertion: true
70-
```
71-
7261
# Badge
7362

7463
To indicate that your project is using Solid Lints, you can use the following badge:

‎example/analysis_options.yaml‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@ include: package:solid_lints/analysis_options.yaml
22

33
plugins:
44
solid_lints:
5-
6-
solid_lints:
7-
diagnostics:
8-
cyclomatic_complexity:
9-
max_complexity: 4
10-
number_of_parameters:
11-
max_parameters: 2
12-
function_lines_of_code:
13-
max_lines: 50
14-
avoid_non_null_assertion: true
15-
avoid_late_keyword: true
16-
avoid_global_state: true
17-
avoid_returning_widgets: true
18-
avoid_unnecessary_setstate: true
19-
double_literal_format: true
20-
avoid_unnecessary_type_assertions: true
21-
avoid_debug_print_in_release: true
22-
avoid_using_api:
23-
severity: info
24-
entries:
25-
- class_name: Future
26-
identifier: wait
27-
source: dart:async
28-
reason: "Future.wait should be avoided because it looses type safety for the results. Use a Record's `wait` method instead."
29-
severity: warning
5+
path: ../
6+
diagnostics:
7+
cyclomatic_complexity:
8+
max_complexity: 4
9+
number_of_parameters:
10+
max_parameters: 2
11+
function_lines_of_code:
12+
max_lines: 50
13+
avoid_non_null_assertion: true
14+
avoid_late_keyword: true
15+
avoid_global_state: true
16+
avoid_returning_widgets: true
17+
avoid_unnecessary_setstate: true
18+
double_literal_format: true
19+
avoid_unnecessary_type_assertions: true
20+
avoid_debug_print_in_release: true
21+
avoid_using_api:
22+
severity: info
23+
entries:
24+
- class_name: Future
25+
identifier: wait
26+
source: dart:async
27+
reason: >-
28+
Future.wait should be avoided because it loses type safety for
29+
the results. Use a Record's `wait` method instead.
30+
severity: warning

‎lib/src/utils/docs_parser/output_formatters/docusaurus_formatter.dart‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:path/path.dart';
44
import 'package:solid_lints/src/utils/docs_parser/models/rule_doc.dart';
55
import 'package:solid_lints/src/utils/docs_parser/output_formatters/markdown_formatter.dart';
66
import 'package:solid_lints/src/utils/docs_parser/output_formatters/rules_documentation_formatter.dart';
7+
import 'package:yaml/yaml.dart';
78

89
/// Formatter that generates markdown files for every separate rule
910
class DocusaurusFormatter implements RulesDocumentationFormatter<void> {
@@ -15,41 +16,58 @@ sidebar_position: 0
1516
1617
1718
''';
19+
static const _latestVersionPlaceholder = '<INSERT LATEST VERSION>';
1820
static final _markdownFormatter = MarkdownFormatter();
1921

2022
final Directory _outputDirectory;
2123
final File _readmeFile;
24+
final File _pubspecFile;
2225

2326
/// DocusaurusFormatter
2427
DocusaurusFormatter({
2528
required String docusaurusDocsDirPath,
2629
required String readmePath,
30+
required String pubspecPath,
2731
}) : _outputDirectory = Directory(docusaurusDocsDirPath),
28-
_readmeFile = File(readmePath);
32+
_readmeFile = File(readmePath),
33+
_pubspecFile = File(pubspecPath);
2934

3035
@override
3136
void format(List<RuleDoc> rules) {
3237
if (!_outputDirectory.existsSync()) {
3338
_outputDirectory.createSync(recursive: true);
3439
}
3540

36-
File(join(_outputDirectory.parent.path, 'intro.md'))
37-
..createSync()
38-
..writeAsStringSync(_introFileMetadata + _readmeFile.readAsStringSync());
41+
final stableVersion = _extractStableVersion();
42+
final readmeContent = _readmeFile.readAsStringSync().replaceAll(
43+
_latestVersionPlaceholder,
44+
stableVersion ?? _latestVersionPlaceholder,
45+
);
46+
47+
File(
48+
join(_outputDirectory.parent.path, 'intro.md'),
49+
).writeAsStringSync('$_introFileMetadata$readmeContent');
3950

4051
rules.forEach(_createMarkdownFileForRule);
4152
}
4253

54+
String? _extractStableVersion() {
55+
if (!_pubspecFile.existsSync()) return null;
56+
try {
57+
final yaml = loadYaml(_pubspecFile.readAsStringSync());
58+
if (yaml case {'version': final String rawVersion}) {
59+
return '^${rawVersion.split(RegExp('[-+]')).first}';
60+
}
61+
} catch (_) {}
62+
return null;
63+
}
64+
4365
void _createMarkdownFileForRule(RuleDoc rule) =>
44-
File(
45-
join(_outputDirectory.path, '${rule.name}.md'),
46-
)
47-
..createSync()
48-
..writeAsString(
49-
_markdownFormatter.formatRuleToMarkdown(
50-
rule,
51-
includeName: false,
52-
parametersAsList: false,
53-
),
54-
);
66+
File(join(_outputDirectory.path, '${rule.name}.md')).writeAsStringSync(
67+
_markdownFormatter.formatRuleToMarkdown(
68+
rule,
69+
includeName: false,
70+
parametersAsList: false,
71+
),
72+
);
5573
}

‎pubspec.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
# More details: https://github.com/dart-lang/sdk/issues/61821
1616
analyzer_plugin: ^0.14.2
1717
analyzer: ^10.0.1
18-
collection: ^1.19.0
18+
collection: ^1.19.1
1919
analysis_server_plugin: ^0.3.3
2020
equatable: ^2.1.0
2121
glob: ^2.1.3
@@ -25,9 +25,9 @@ dependencies:
2525
test: ^1.25.14
2626

2727
dev_dependencies:
28-
args: ^2.6.0
28+
args: ^2.7.0
2929
analyzer_testing: ^0.1.9
30-
test_reflective_loader: ^0.3.0
30+
test_reflective_loader: ^0.4.0
3131

3232
plugin:
3333
platforms:

‎tool/generate_web_docs_content.dart‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import 'package:solid_lints/src/utils/docs_parser/output_formatters/docusaurus_f
66
import 'package:solid_lints/src/utils/docs_parser/parsers/docs_parser.dart';
77

88
void main(List<String> rawArgs) async {
9-
final readmeDefaultPath = join(Directory.current.parent.path, 'README.md');
9+
final projectRoot = File.fromUri(Platform.script).parent.parent.path;
10+
11+
final readmeDefaultPath = join(projectRoot, 'README.md');
12+
final pubspecDefaultPath = join(projectRoot, 'pubspec.yaml');
1013
final docusaurusDefaultPath = join(
11-
Directory.current.parent.path,
14+
projectRoot,
1215
'doc',
1316
'docusaurus',
1417
'docs',
15-
'Lints Documentation',
18+
'2_custom_lints',
1619
);
1720

1821
final argsParser = ArgParser()
@@ -38,6 +41,11 @@ void main(List<String> rawArgs) async {
3841
' copied as docusaurus intro.md',
3942
defaultsTo: readmeDefaultPath,
4043
)
44+
..addOption(
45+
'pubspec',
46+
help: 'Path to the pubspec.yaml file',
47+
defaultsTo: pubspecDefaultPath,
48+
)
4149
..addMultiOption(
4250
'suffixes',
4351
help: 'Filename suffixes that should be parsed',
@@ -55,6 +63,7 @@ void main(List<String> rawArgs) async {
5563
formatter: DocusaurusFormatter(
5664
docusaurusDocsDirPath: args['docs-dir'],
5765
readmePath: args['readme'],
66+
pubspecPath: args['pubspec'],
5867
),
5968
ruleFileSuffixes: args['suffixes'],
6069
).parse(Directory(path));

0 commit comments

Comments
 (0)