-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate data source from rules.json to messages.yaml #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r0227n
wants to merge
64
commits into
main
Choose a base branch
from
improve/update-source-rules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+770
−188
Open
Changes from 59 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
4b904de
feat: Change Rule property for yaml
r0227n 0a2c195
feat: Change information source from json to yaml
r0227n c3f612c
chor: Move convertToJsonFromYaml method into getRules method
r0227n 755424d
fix: Add dependencies and remove ignore
r0227n 032279a
fix: state and categories no longer output non-existent values.
r0227n 17c63a1
chore: Minimized roop processing
r0227n 25b02fd
add: convertToJsonFromYaml method test code
r0227n a4a2a98
refactor: simplify convertToJsonFromYaml method and optimize YAML map…
blendthink cf2a1ea
feat: add toJson extension method to YamlMap to simplify YAML map to …
blendthink 2e51eff
fix: add exception handling for non-YamlMap entry values and improve …
blendthink 67c16ff
test: add unit tests for YamlMap's toJson method
blendthink 3e1ee91
refactor: remove convertToJsonFromYaml method and directly convert YA…
blendthink 4ee2737
fix: typo ( exsistsCategories → existsCategories )
blendthink 67b2bde
docs: add example YAML data to explain shared rule categories
blendthink aead3af
refactor: rename variable to better reflect its purpose
blendthink 9188e2c
docs: add comment explaining rule addition conditions
blendthink d1be457
add: Create DTO for LintCode
r0227n 6341baa
refactor: Changed to separate processing by presence/absence of Share…
r0227n e6214a1
refactor: Sort output results alphabetically
r0227n 30a0f50
chore: Chnage details property to non null
r0227n 21adaa6
refactor: Improve null safety and readability of sharedName processing
blendthink 9bb0f31
refactor: Improve variable names to clarify type information and grou…
blendthink 1517d2e
refactor: Improve variable names representing grouped LintCodeDto to …
blendthink d826011
refactor: Replace firstWhere with map and nonNulls to enhance null sa…
blendthink 5c8c20f
refactor: Change variable names to plural to clarify that they repres…
blendthink dc9a41f
refactor: Add null checks and error handling for required fields
blendthink 2b4c91e
refactor: Add processing for DTOs without sharedName and strengthen n…
blendthink 80d88af
refactor: Store rule merging process in allRules variable to improve …
blendthink 1685344
refactor: Change to call toList() after sorting
blendthink e8770c9
docs: Add comments to each processing step to clarify code flow
blendthink ee2373f
Refactor variable names for consistency
blendthink 5e468a9
Remove unnecessary toList() conversion
blendthink b78e7bd
fix: Change AsyncMemoizer type from Iterable to List for consistency …
r0227n cb7abb6
chore: delete canConvertToRule method
r0227n 65985e2
feat: implement LintCodeDtoMapper for converting LintCodeDto to Rule
r0227n 7fc017e
fix: filter LintCodeDtos by canConvertToRule in groupedLintCodeDtosBy…
r0227n cf148f2
fix: correct property name check in toRuleFromDtos method
r0227n a2b0a81
test: add unit tests for LintCodeDtoMapper methods
r0227n 5e06864
fix: lint warning for unnecessary_non_null_assertion
r0227n c256789
fix: change return type of getRules method to List<Rule>
r0227n 871862b
fix: format
r0227n b0db03a
refactor: extract grouping and filtering logic for LintCodeDto to Lin…
r0227n 2895b6c
delete: canConvertToRule
r0227n c32423f
refactor: delegate rule conversion logic to LintCodeDtoMapper
r0227n 388411b
test: update state assertions in LintCodeDtoMapper tests
r0227n 64d2fa9
refactor: simplify mapping of LintCodeDto to Rule in toRules method
r0227n 9ada809
chore: Cancel the modifications made in 0a2c195f5d6bec090a35d8fb294e6…
r0227n 2edc37d
chore ; LintCodeDto grouping process is no longer a function cutout.
r0227n 39dea49
fix shared DTOs grouping logic to handle partial data
r0227n 9bce333
refacotr: Delete toRuleFromDtos and merge toRule
r0227n da2e1fc
chore: Remove the where condition “state is only active”.
r0227n 1ccc1c2
fix: Fixed to consider active/inactive and determine if version supports
r0227n c8191bc
chore: Fix the where condition because some values have no properties…
r0227n de3e1ec
chore: Move ExtState to a file defined by State
r0227n 7711233
add: visibleForTesting annotation
r0227n 2bd92cc
fix: Fix tests as mapper class is modified.
r0227n 535e765
chore: remove incorrect visibleForTesting annotation
r0227n 7d0b4f9
fix: The condition sharedName is null and state is not null does not …
r0227n 763e64c
refactor: Rewrote method to directly assign parameters and create Rul…
r0227n ff06585
rename: Rename mapper class & method
r0227n 7f37d0f
chore: Modified test cases due to function argument changes
r0227n a7c019a
chore: Support for renaming staging leaks
r0227n 973b4a1
add: Correction of forgetting to add required
r0227n 8ff0798
chore: The “categories ? []” in the comments for the reason.
r0227n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
tools/update_lint_rules/lib/src/extension/yaml_map_ext.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:yaml/yaml.dart'; | ||
|
||
extension YamlMapToJson on YamlMap { | ||
Map<String, dynamic> toJson() { | ||
final jsonString = jsonEncode(this); | ||
return jsonDecode(jsonString); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
tools/update_lint_rules/lib/src/mappers/lint_code_dto_mapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:update_lint_rules/src/models/lint_code_dto.dart'; | ||
import 'package:update_lint_rules/src/models/lint_rule.dart'; | ||
|
||
class LintCodeDtoMapper { | ||
const LintCodeDtoMapper._(); | ||
|
||
/// Builds a [Rule] instance from provided parameters. | ||
/// | ||
/// If any of the required parameters categories, details, or state | ||
/// is null. The [FormatException] message includes which fields are missing. | ||
@visibleForTesting | ||
static Rule buildRule({ | ||
required String name, | ||
List<String>? categories, | ||
String? details, | ||
Map<String, dynamic>? state, | ||
}) { | ||
if (categories == null || details == null || state == null) { | ||
throw FormatException( | ||
'The required field for the $name is null: ${[if (categories == null) 'categories', if (details == null) 'details', if (state == null) 'state'].join(', ')}', | ||
); | ||
} | ||
|
||
return Rule( | ||
name: name, | ||
categories: categories, | ||
details: details, | ||
state: state.map( | ||
(key, value) => | ||
MapEntry(RuleState.values.byName(key), Since.fromJson(value)), | ||
), | ||
); | ||
} | ||
|
||
/// Convert a list of [LintCodeDto] to a list of [Rule] | ||
static List<Rule> toRules(Iterable<LintCodeDto> dtos) { | ||
// Group DTOs by sharedName | ||
final groupedLintCodeDtosBySharedName = dtos | ||
.where((dto) => dto.sharedName != null) | ||
// If `dto.sharedName` is not null, `dto.name` is the same as `dto.sharedName`. | ||
// So, group by `dto.name`. | ||
.groupListsBy((dto) => dto.name); | ||
|
||
// Convert DTOs with sharedName to Rules | ||
final rulesWithSharedName = groupedLintCodeDtosBySharedName.entries.map(( | ||
e, | ||
) { | ||
final dtos = e.value; | ||
|
||
final categories = dtos.map((e) => e.categories).nonNulls.firstOrNull; | ||
final deprecatedDetails = | ||
dtos.map((e) => e.deprecatedDetails).nonNulls.firstOrNull; | ||
final state = dtos.map((e) => e.state).nonNulls.firstOrNull; | ||
|
||
return LintCodeDtoMapper.buildRule( | ||
name: e.key, | ||
categories: categories, | ||
details: deprecatedDetails, | ||
state: state, | ||
); | ||
}); | ||
|
||
// Convert DTOs without sharedName to Rules | ||
final rulesWithoutSharedName = dtos | ||
.where((dto) => dto.sharedName == null) | ||
.map( | ||
(dto) => LintCodeDtoMapper.buildRule( | ||
name: dto.name, | ||
categories: dto.categories ?? const [], | ||
details: dto.deprecatedDetails, | ||
state: dto.state, | ||
), | ||
); | ||
|
||
final allRules = [...rulesWithSharedName, ...rulesWithoutSharedName]; | ||
// Filter out inactive rules and sort by name | ||
return allRules.sorted((a, b) => a.name.compareTo(b.name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'lint_code_dto.freezed.dart'; | ||
part 'lint_code_dto.g.dart'; | ||
|
||
@freezed | ||
sealed class LintCodeDto with _$LintCodeDto { | ||
factory LintCodeDto({ | ||
required String name, | ||
required String? sharedName, | ||
required String? problemMessage, | ||
required String? correctionMessage, | ||
required Map<String, dynamic>? state, | ||
required List<String>? categories, | ||
required bool? hasPublishedDocs, | ||
required String? documentation, | ||
required String? deprecatedDetails, | ||
required String? todo, | ||
}) = _LintCodeDto; | ||
|
||
factory LintCodeDto.fromJson(Map<String, dynamic> json) => | ||
_$LintCodeDtoFromJson(json); | ||
} |
191 changes: 191 additions & 0 deletions
191
tools/update_lint_rules/lib/src/models/lint_code_dto.freezed.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
tools/update_lint_rules/lib/src/models/lint_code_dto.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since data such as always_require_non_null_named_parameters's for which
category
is null already exists, an empty character is assigned whencategory
is null.