@sun-asterisk/sunlint 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.sunlint.json +1 -1
  2. package/CHANGELOG.md +83 -0
  3. package/README.md +66 -4
  4. package/config/presets/all.json +125 -0
  5. package/config/presets/beginner.json +16 -8
  6. package/config/presets/ci.json +12 -4
  7. package/config/presets/maintainability.json +38 -0
  8. package/config/presets/performance.json +32 -0
  9. package/config/presets/quality.json +103 -0
  10. package/config/presets/recommended.json +36 -12
  11. package/config/presets/security.json +88 -0
  12. package/config/presets/strict.json +15 -5
  13. package/config/rules/rules-registry-generated.json +6312 -0
  14. package/config/rules-summary.json +1941 -0
  15. package/core/adapters/sunlint-rule-adapter.js +452 -0
  16. package/core/analysis-orchestrator.js +4 -4
  17. package/core/config-manager.js +28 -5
  18. package/core/rule-selection-service.js +52 -55
  19. package/docs/CONFIGURATION.md +111 -3
  20. package/docs/LANGUAGE-SPECIFIC-RULES.md +308 -0
  21. package/docs/README.md +3 -0
  22. package/docs/STANDARDIZED-CATEGORY-FILTERING.md +156 -0
  23. package/engines/eslint-engine.js +92 -2
  24. package/engines/heuristic-engine.js +8 -31
  25. package/origin-rules/common-en.md +1320 -0
  26. package/origin-rules/dart-en.md +289 -0
  27. package/origin-rules/java-en.md +60 -0
  28. package/origin-rules/kotlin-mobile-en.md +453 -0
  29. package/origin-rules/reactjs-en.md +102 -0
  30. package/origin-rules/security-en.md +1055 -0
  31. package/origin-rules/swift-en.md +449 -0
  32. package/origin-rules/typescript-en.md +136 -0
  33. package/package.json +6 -5
  34. package/scripts/copy-rules.js +86 -0
  35. package/rules/README.md +0 -252
  36. package/rules/common/C002_no_duplicate_code/analyzer.js +0 -65
  37. package/rules/common/C002_no_duplicate_code/config.json +0 -23
  38. package/rules/common/C003_no_vague_abbreviations/analyzer.js +0 -418
  39. package/rules/common/C003_no_vague_abbreviations/config.json +0 -35
  40. package/rules/common/C006_function_naming/analyzer.js +0 -349
  41. package/rules/common/C006_function_naming/config.json +0 -86
  42. package/rules/common/C010_limit_block_nesting/analyzer.js +0 -389
  43. package/rules/common/C013_no_dead_code/analyzer.js +0 -206
  44. package/rules/common/C014_dependency_injection/analyzer.js +0 -338
  45. package/rules/common/C017_constructor_logic/analyzer.js +0 -314
  46. package/rules/common/C019_log_level_usage/analyzer.js +0 -362
  47. package/rules/common/C019_log_level_usage/config.json +0 -121
  48. package/rules/common/C029_catch_block_logging/analyzer.js +0 -373
  49. package/rules/common/C029_catch_block_logging/config.json +0 -59
  50. package/rules/common/C031_validation_separation/analyzer.js +0 -186
  51. package/rules/common/C041_no_sensitive_hardcode/analyzer.js +0 -292
  52. package/rules/common/C042_boolean_name_prefix/analyzer.js +0 -300
  53. package/rules/common/C043_no_console_or_print/analyzer.js +0 -304
  54. package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +0 -351
  55. package/rules/common/C075_explicit_return_types/analyzer.js +0 -103
  56. package/rules/common/C076_single_test_behavior/analyzer.js +0 -121
  57. package/rules/docs/C002_no_duplicate_code.md +0 -57
  58. package/rules/docs/C031_validation_separation.md +0 -72
  59. package/rules/index.js +0 -149
  60. package/rules/migration/converter.js +0 -385
  61. package/rules/migration/mapping.json +0 -164
  62. package/rules/security/S026_json_schema_validation/analyzer.js +0 -251
  63. package/rules/security/S026_json_schema_validation/config.json +0 -27
  64. package/rules/security/S027_no_hardcoded_secrets/analyzer.js +0 -263
  65. package/rules/security/S027_no_hardcoded_secrets/config.json +0 -29
  66. package/rules/security/S029_csrf_protection/analyzer.js +0 -264
  67. package/rules/tests/C002_no_duplicate_code.test.js +0 -50
  68. package/rules/universal/C010/generic.js +0 -0
  69. package/rules/universal/C010/tree-sitter-analyzer.js +0 -0
  70. package/rules/utils/ast-utils.js +0 -191
  71. package/rules/utils/base-analyzer.js +0 -98
  72. package/rules/utils/pattern-matchers.js +0 -239
  73. package/rules/utils/rule-helpers.js +0 -264
  74. package/rules/utils/severity-constants.js +0 -93
@@ -0,0 +1,289 @@
1
+ # 📘 Dart Specific Coding Rules
2
+
3
+ ---
4
+
5
+ ### 📘 Rule D001 – Keep parameter names consistent when overriding methods
6
+
7
+ - **Objective**: Maintain consistency between inherited classes
8
+ - **Details**: Do not change parameter names when overriding to maintain consistency in meaning and documentation of parameters if available.
9
+ - **Applies to**: Flutter/Dart
10
+ - **Tools**: `dart lint` (`avoid_renaming_method_parameters`)
11
+ - **Principles**: CODE_QUALITY
12
+ - **Version**: 1.0
13
+ - **Status**: activated
14
+ - **Severity**: major
15
+
16
+ ### 📘 Rule D002 – Avoid using single cascade (..) operators
17
+
18
+ - **Objective**: Write clear, readable code
19
+ - **Details**: Only use cascade (`..`) when performing multiple consecutive operations on the same object. Avoid using it for single operations.
20
+ - **Applies to**: Flutter/Dart
21
+ - **Tools**: `dart lint` (`avoid_single_cascade_in_expression_statements`)
22
+ - **Principles**: CODE_QUALITY
23
+ - **Version**: 1.0
24
+ - **Status**: activated
25
+ - **Severity**: major
26
+
27
+ ### 📘 Rule D003 – Avoid calling methods/accessing properties on dynamic types
28
+
29
+ - **Objective**: Prevent runtime errors due to lack of type checking
30
+ - **Details**: Avoid using `dynamic.foo()` or `dynamic.bar` without proper checking
31
+ - **Applies to**: Flutter/Dart
32
+ - **Tools**: `dart lint` (`avoid_dynamic_calls`)
33
+ - **Principles**: CODE_QUALITY, SECURITY
34
+ - **Version**: 1.0
35
+ - **Status**: activated
36
+ - **Severity**: critical
37
+
38
+ ### 📘 Rule D004 – Use standard `package:` imports
39
+
40
+ - **Objective**: Reduce confusion in imports
41
+ - **Details**: Avoid mixing relative and package imports which can cause circular errors or alias errors when a file is imported in two different ways.
42
+ - **Applies to**: Flutter/Dart
43
+ - **Tools**: `dart lint` (`always_use_package_imports`)
44
+ - **Principles**: CODE_QUALITY
45
+ - **Version**: 1.0
46
+ - **Status**: activated
47
+ - **Severity**: major
48
+
49
+ ### 📘 Rule D005 – Always declare function return types
50
+
51
+ - **Objective**: Clarify logic and increase reliability in type checking
52
+ - **Details**:
53
+ - Avoid `dynamic` returns or unclear type inference
54
+ - Helps analyzer perform more complete code analysis to find potential runtime errors
55
+ - **Applies to**: Flutter/Dart
56
+ - **Tools**: `dart lint` (`always_declare_return_types`)
57
+ - **Principles**: CODE_QUALITY
58
+ - **Version**: 1.0
59
+ - **Status**: activated
60
+ - **Severity**: major
61
+
62
+ ### 📘 Rule D006 – Do not override `==` and `hashCode` in mutable classes
63
+
64
+ - **Objective**: Prevent logic errors when using mutable objects in collections.
65
+ - **Details**: Equality should be based on immutable values
66
+ - **Applies to**: Flutter/Dart
67
+ - **Tools**: `dart lint` (`avoid_equals_and_hash_code_on_mutable_classes`)
68
+ - **Principles**: CODE_QUALITY
69
+ - **Version**: 1.0
70
+ - **Status**: activated
71
+ - **Severity**: critical
72
+
73
+ ### 📘 Rule D007 – Do not pass default values when calling functions
74
+
75
+ - **Objective**: Avoid redundancy and clarify intent
76
+ - **Details**: If a function has default parameters, no need to pass the same value again
77
+ - **Applies to**: Flutter/Dart
78
+ - **Tools**: `dart lint` (`avoid_redundant_argument_values`)
79
+ - **Principles**: CODE_QUALITY, PERFORMANCE
80
+ - **Version**: 1.0
81
+ - **Status**: activated
82
+ - **Severity**: major
83
+
84
+ ### 📘 Rule D008 – Avoid slow async functions in `dart:io`
85
+
86
+ - **Objective**: Optimize I/O performance
87
+ - **Details**: Avoid the following slow async functions:
88
+ - `Directory.exists`
89
+ - `Directory.stat`
90
+ - `File.lastModified`
91
+ - `File.exists`
92
+ - `File.stat`
93
+ - `FileSystemEntity.isDirectory`
94
+ - `FileSystemEntity.isFile`
95
+ - `FileSystemEntity.isLink`
96
+ - `FileSystemEntity.type`
97
+ - **Applies to**: Flutter/Dart
98
+ - **Tools**: `dart lint` (`avoid_slow_async_io`)
99
+ - **Principles**: CODE_QUALITY, PERFORMANCE
100
+ - **Version**: 1.0
101
+ - **Status**: activated
102
+ - **Severity**: major
103
+
104
+ ### 📘 Rule D009 – Do not use throw or control flow in `finally`
105
+
106
+ - **Objective**: Avoid unexpected behavior
107
+ - **Details**: Do not use `return`, `break`, `throw` in `finally` blocks
108
+ - **Applies to**: Flutter/Dart
109
+ - **Tools**: `dart lint` (`control_flow_in_finally`, `throw_in_finally`)
110
+ - **Principles**: CODE_QUALITY
111
+ - **Version**: 1.0
112
+ - **Status**: activated
113
+ - **Severity**: critical
114
+
115
+ ### 📘 Rule D010 – Handle all cases when using `switch` with enums or enum-like classes
116
+
117
+ - **Objective**: Avoid missing cases
118
+ - **Details**: When using `switch` with `enum`, always handle all cases completely.
119
+ - **Applies to**: Flutter/Dart
120
+ - **Tools**: `dart lint` (`exhaustive_cases`)
121
+ - **Principles**: CODE_QUALITY
122
+ - **Version**: 1.0
123
+ - **Status**: activated
124
+ - **Severity**: major
125
+
126
+ ### 📘 Rule D011 – Avoid importing `.dart` files from `lib/src` of other packages
127
+
128
+ - **Objective**: Avoid unstable dependencies that cause breaking changes.
129
+ - **Details**: Only import from public API (`lib/src`) within the same package, not from other packages.
130
+ - **Applies to**: Flutter/Dart
131
+ - **Tools**: `dart lint` (`implementation_imports`)
132
+ - **Principles**: CODE_QUALITY, SECURITY
133
+ - **Version**: 1.0
134
+ - **Status**: activated
135
+ - **Severity**: major
136
+
137
+ ### 📘 Rule D012 – Avoid passing null to closure parameters
138
+
139
+ - **Objective**: Prevent runtime exceptions
140
+ - **Details**: Typically, a closure passed to a method will only be called conditionally, using `null` will lead to exceptions or unexpected logic.
141
+ - **Applies to**: Flutter/Dart
142
+ - **Tools**: `dart lint` (`null_closures`)
143
+ - **Principles**: CODE_QUALITY, SECURITY
144
+ - **Version**: 1.0
145
+ - **Status**: activated
146
+ - **Severity**: major
147
+
148
+ ### 📘 Rule D013 – Use adjacent strings or interpolation to create strings
149
+
150
+ - **Objective**: Easier to read and more efficient
151
+ - **Details**: Use adjacent strings or interpolation to create strings
152
+ - **Applies to**: Flutter/Dart
153
+ - **Tools**: `dart lint` (`prefer_adjacent_string_concatenation`, `prefer_interpolation_to_compose_strings`)
154
+ - **Principles**: CODE_QUALITY, PERFORMANCE
155
+ - **Version**: 1.0
156
+ - **Status**: activated
157
+ - **Severity**: major
158
+
159
+ ### 📘 Rule D014 – Use conditional assignment `??=` instead of `if-null-then-assign`
160
+
161
+ - **Objective**: More concise and clear meaning
162
+ - **Details**: Use `a ??= b` instead of `if (a == null) a = b;`
163
+ - **Applies to**: Flutter/Dart
164
+ - **Tools**: `dart lint` (`prefer_conditional_assignment`)
165
+ - **Principles**: CODE_QUALITY, MAINTAINABILITY
166
+ - **Version**: 1.0
167
+ - **Status**: activated
168
+ - **Severity**: major
169
+
170
+ ### 📘 Rule D015 – Use `final`, `const` for immutable variables
171
+
172
+ - **Objective**: Prevent bugs from unintended value changes
173
+ - **Details**: Use `final` or `const` for variables that don't change throughout their lifetime
174
+ - **Applies to**: Flutter/Dart
175
+ - **Tools**: `dart lint` (`prefer_final_fields`, `prefer_const_declarations`, `prefer_const_constructors`)
176
+ - **Principles**: CODE_QUALITY
177
+ - **Version**: 1.0
178
+ - **Status**: activated
179
+ - **Severity**: major
180
+
181
+ ### 📘 Rule D016 – Use explicit definitions for function types in parameters
182
+
183
+ - **Objective**: Increase clarity and accurate type checking
184
+ - **Details**: Use `generic function type syntax` for parameters.
185
+ - **Applies to**: Flutter/Dart
186
+ - **Tools**: `dart lint` (`use_function_type_syntax_for_parameters`)
187
+ - **Principles**: CODE_QUALITY
188
+ - **Version**: 1.0
189
+ - **Status**: activated
190
+ - **Severity**: major
191
+
192
+ ### 📘 Rule D017 – Ensure simple and correct Regex syntax
193
+
194
+ - **Objective**: Prevent logic errors from invalid expressions
195
+ - **Details**: Use clear, simple Regex patterns. Avoid incorrect or overly complex expressions
196
+ - **Applies to**: Flutter/Dart
197
+ - **Tools**: `dart lint` (`valid_regexps`)
198
+ - **Principles**: CODE_QUALITY
199
+ - **Version**: 1.0
200
+ - **Status**: activated
201
+ - **Severity**: major
202
+
203
+ ### 📘 Rule D018 – Use `rethrow` instead of `throw` when re-throwing errors
204
+
205
+ - **Objective**: Preserve original error stack trace
206
+ - **Details**: In catch blocks, use `rethrow` to re-throw the same caught error
207
+ - **Applies to**: Flutter/Dart
208
+ - **Tools**: `dart lint` (`use_rethrow_when_possible`)
209
+ - **Principles**: CODE_QUALITY
210
+ - **Version**: 1.0
211
+ - **Status**: activated
212
+ - **Severity**: major
213
+
214
+ ### 📘 Rule D019 – Use `isEmpty` / `isNotEmpty` for String, Iterable and Map
215
+
216
+ - **Objective**: Clear meaning and better performance
217
+ - **Details**: Instead of `list.length == 0`, use `list.isEmpty`
218
+ - **Applies to**: Flutter/Dart
219
+ - **Tools**: `dart lint` (`prefer_is_empty`, `prefer_is_not_empty`)
220
+ - **Principles**: CODE_QUALITY
221
+ - **Version**: 1.0
222
+ - **Status**: activated
223
+ - **Severity**: major
224
+
225
+ ### 📘 Rule D020 – Ensure valid URLs in `pubspec.yaml`
226
+
227
+ - **Objective**: Avoid metadata errors and poor security
228
+ - **Details**: Do not use `http://` or placeholder URLs like `example.com`
229
+ - **Applies to**: Flutter/Dart
230
+ - **Tools**: `dart lint` (`secure_pubspec_urls`)
231
+ - **Principles**: SECURITY
232
+ - **Version**: 1.0
233
+ - **Status**: activated
234
+ - **Severity**: major
235
+
236
+ ### 📘 Rule D021 – Use `BuildContext` synchronously
237
+
238
+ - **Objective**: Prevent errors when `context` changes after `await`
239
+ - **Details**: Use `BuildContext` carefully in asynchronous functions
240
+ - **Applies to**: Flutter/Dart
241
+ - **Tools**: `flutter_lints` (`use_build_context_synchronously`)
242
+ - **Principles**: CODE_QUALITY
243
+ - **Version**: 1.0
244
+ - **Status**: activated
245
+ - **Severity**: critical
246
+
247
+ ### 📘 Rule D022 – Place `child:` at the end when constructing widgets
248
+
249
+ - **Objective**: Help readability of widget tree and UI structure
250
+ - **Details**: Parameters like `child`, `children` should be placed last in widget constructors
251
+ - **Applies to**: Flutter/Dart
252
+ - **Tools**: `flutter_lints` (`sort_child_properties_last`)
253
+ - **Principles**: CODE_QUALITY
254
+ - **Version**: 1.0
255
+ - **Status**: activated
256
+ - **Severity**: major
257
+
258
+ ### 📘 Rule D023 – Prefer using `contains` for `List` and `String`
259
+
260
+ - **Objective**: Easier to read and more efficient
261
+ - **Details**: Use `contains` instead of `indexOf` to check for element existence in `List` or `String`.
262
+ - **Applies to**: Flutter/Dart
263
+ - **Tools**: `dart lint` (`prefer_contains`)
264
+ - **Principles**: CODE_QUALITY, SECURITY
265
+ - **Version**: 1.0
266
+ - **Status**: activated
267
+ - **Severity**: major
268
+
269
+ ### 📘 Rule D024 – Use `??` to convert `null` to `bool`
270
+
271
+ - **Objective**: Write concisely and avoid null exceptions
272
+ - **Details**: Use `flag ?? false` instead of `flag == null ? false : flag`
273
+ - **Applies to**: Flutter/Dart
274
+ - **Tools**: `dart lint` (`use_if_null_to_convert_nulls_to_bools`)
275
+ - **Principles**: CODE_QUALITY, SECURITY
276
+ - **Version**: 1.0
277
+ - **Status**: activated
278
+ - **Severity**: major
279
+
280
+ ### 📘 Rule D025 – Include `Key` in Widget constructors
281
+
282
+ - **Objective**: Help Flutter identify widgets, ensure efficient rebuilds and prevent errors when reordering widgets.
283
+ - **Details**: Use `key` in all public widget constructors
284
+ - **Applies to**: Flutter/Dart
285
+ - **Tools**: `flutter_lints` (`use_key_in_widget_constructors`)
286
+ - **Principles**: CODE_QUALITY, USABILITY, PERFORMANCE
287
+ - **Version**: 1.0
288
+ - **Status**: activated
289
+ - **Severity**: major
@@ -0,0 +1,60 @@
1
+ # 📘 Java Specific Coding Rules
2
+
3
+ ### 📘 Rule J001 – Use Null Object or Optional instead of repetitive null checks
4
+
5
+ - **Objective**: Reduce the risk of NullPointerException (NPE) and avoid repeating `if (x != null)` throughout the code.
6
+ - **Details**:
7
+ - Encourage using `Optional`, the Null Object Pattern, or guard clauses to handle potential null values.
8
+ - **Applies to**: Java/Kotlin
9
+ - **Tools**: Linter, PR guideline
10
+ - **Principles**: CODE_QUALITY
11
+
12
+ ### 📘 Rule J002 – Do not use `null` as a default value unless absolutely necessary
13
+
14
+ - **Objective**: Prevent NullPointerException by promoting clearer use of Optional or nullable types.
15
+ - **Details**:
16
+ - Prefer using `Optional`, explicitly nullable types, or well-defined default values.
17
+ - Ensure `null` is checked and handled at system boundaries (e.g., during input validation).
18
+ - **Applies to**: Java/Kotlin
19
+ - **Tools**: Static Analyzer
20
+ - **Principles**: CODE_QUALITY
21
+
22
+ ### 📘 Rule J003 – Every enum must provide a clear toString or description when used in UI/logs
23
+
24
+ - **Objective**: Avoid unclear log messages such as `STATUS_1`, and improve readability.
25
+ - **Details**:
26
+ - Add methods like `getLabel()` or override `toString()` for enums used in UI or logs.
27
+ - Avoid default enum output (e.g., raw index or unclear names).
28
+ - **Applies to**: Java/Kotlin
29
+ - **Tools**: Manual Review, Enum Linter
30
+ - **Principles**: CODE_QUALITY
31
+
32
+ ### 📘 Rule J004 – Avoid creating enums/classes just to wrap fixed constants
33
+
34
+ - **Objective**: Prevent unnecessary abstractions that clutter the codebase.
35
+ - **Details**:
36
+ - Use enums only when modeling meaningful state, not just as a container for constants.
37
+ - Reuse existing config/shared constants instead of creating new wrapper classes.
38
+ - **Applies to**: Java/Kotlin
39
+ - **Tools**: Review or static pattern detector
40
+ - **Principles**: CODE_QUALITY
41
+
42
+ ### 📘 Rule J005 – Always use `final` or `const` for variables that do not change
43
+
44
+ - **Objective**: Clearly express intent and prevent unintended modifications.
45
+ - **Details**:
46
+ - Variables that are never reassigned should be declared as `final` (Java) or `const` (in other applicable languages).
47
+ - This helps reviewers, compilers, and future developers understand the variable's purpose.
48
+ - **Applies to**: Java/Kotlin
49
+ - **Tools**: Linter, Static Analyzer
50
+ - **Principles**: CODE_QUALITY
51
+
52
+ ### 📘 Rule J006 – Do not override methods without calling `super` when required
53
+
54
+ - **Objective**: Preserve expected behavior and side effects in inherited logic.
55
+ - **Details**:
56
+ - If the superclass method has side effects, ensure to call `super.method()` when overriding.
57
+ - Only omit `super` if you're completely replacing the logic intentionally.
58
+ - **Applies to**: Java/Kotlin
59
+ - **Tools**: Linter, Manual Review
60
+ - **Principles**: CODE_QUALITY