-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Add pubspec.lock to .gitignore * feat: Add `avoid_hardcoded_japanese` rule * chore: Update dependencies and add code check workflow * chore: Add doc comment
- Loading branch information
Showing
17 changed files
with
180 additions
and
775 deletions.
There are no files selected for viewing
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,38 @@ | ||
name: code check | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
analyze: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: subosito/flutter-action@v2 | ||
with: | ||
channel: 'stable' | ||
cache: true | ||
|
||
- name: Install Melos | ||
uses: bluefireteam/melos-action@v3 | ||
|
||
- name: Analyze packages | ||
run: melos analyze | ||
|
||
- name: Custom lint | ||
run: melos custom_lint | ||
|
||
- name: Check for the existence of unformatted files | ||
# Cannot use `melos format` as it requires excluding files generated from the target file | ||
run: melos run format:ci --no-select |
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
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
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
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# https://pub.dev/packages/altive_lints | ||
include: package:altive_lints/altive_lints.yaml | ||
analyzer: | ||
plugins: | ||
- custom_lint | ||
|
||
custom_lint: | ||
rules: | ||
# Unnecessary if not localizing or not using Japanese. | ||
# - avoid_hardcoded_japanese: false |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,4 +10,6 @@ dependencies: | |
sdk: flutter | ||
|
||
dev_dependencies: | ||
altive_lints: ^1.10.0 | ||
altive_lints: | ||
path: ../ | ||
custom_lint: ^0.6.4 |
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,12 @@ | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
|
||
import 'src/lints/avoid_hardcoded_japanese.dart'; | ||
|
||
PluginBase createPlugin() => _AltivePlugin(); | ||
|
||
class _AltivePlugin extends PluginBase { | ||
@override | ||
List<LintRule> getLintRules(CustomLintConfigs configs) => [ | ||
const AvoidHardcodedJapanese(), | ||
]; | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/altive_lints/lib/src/lints/avoid_hardcoded_japanese.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,64 @@ | ||
import 'package:analyzer/error/listener.dart'; | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
|
||
/// An `avoid_hardcoded_japanese` rule which detects | ||
/// and reports hardcoded Japanese text strings within the code. | ||
/// | ||
/// This rule ensures that all user-facing text is | ||
/// properly internationalized to support Japanese localization efforts. | ||
/// | ||
/// ### Example | ||
/// | ||
/// #### BAD: | ||
/// | ||
/// ```dart | ||
/// final message = 'こんにちは'; // LINT | ||
/// print('エラーが発生しました'); // LINT | ||
/// ``` | ||
/// | ||
/// #### GOOD: | ||
/// | ||
/// ```dart | ||
/// final message = AppLocalizations.of(context).hello; | ||
/// print(AppLocalizations.of(context).errorOccurred); | ||
/// ``` | ||
/// | ||
class AvoidHardcodedJapanese extends DartLintRule { | ||
const AvoidHardcodedJapanese() : super(code: _code); | ||
|
||
static const _code = LintCode( | ||
name: 'avoid_hardcoded_japanese', | ||
problemMessage: 'This string appears to be untranslated to Japanese.\n' | ||
'Ensure all user-facing text is properly internationalized for ' | ||
'Japanese localization.', | ||
); | ||
|
||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ErrorReporter reporter, | ||
CustomLintContext context, | ||
) { | ||
context.registry.addSimpleStringLiteral((node) { | ||
final stringValue = node.stringValue; | ||
if (stringValue == null) { | ||
return; | ||
} | ||
if (isJapanese(stringValue)) { | ||
reporter.reportErrorForNode(_code, node); | ||
} | ||
}); | ||
|
||
context.registry.addStringInterpolation((node) { | ||
final stringValue = node.toSource(); | ||
if (isJapanese(stringValue)) { | ||
reporter.reportErrorForNode(_code, node); | ||
} | ||
}); | ||
} | ||
|
||
/// Checks if the string contains Japanese characters | ||
/// (Hiragana, Katakana, Kanji). | ||
bool isJapanese(String value) => | ||
RegExp(r'[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FD0]').hasMatch(value); | ||
} |
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,5 @@ | ||
# https://pub.dev/packages/altive_lints | ||
include: package:altive_lints/altive_lints.yaml | ||
analyzer: | ||
plugins: | ||
- custom_lint |
12 changes: 12 additions & 0 deletions
12
packages/altive_lints/lint_test/lints/avoid_hardcoded_japanese.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,12 @@ | ||
// Check the `avoid_hardcoded_japanese` rule. | ||
|
||
// expect_lint: avoid_hardcoded_japanese | ||
const hiragana = 'あいうえお'; | ||
|
||
// expect_lint: avoid_hardcoded_japanese | ||
const katakana = 'アイウエオ'; | ||
|
||
// expect_lint: avoid_hardcoded_japanese | ||
const kanji = '漢字'; | ||
|
||
const notJapanese = 'abc'; |
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,11 @@ | ||
name: altive_lints_test | ||
description: A starting point for Dart libraries or applications. | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.0.0 | ||
|
||
dev_dependencies: | ||
altive_lints: | ||
path: ../ | ||
custom_lint: ^0.6.4 |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -13,3 +13,7 @@ topics: | |
|
||
environment: | ||
sdk: ^3.0.0 | ||
|
||
dependencies: | ||
analyzer: ^6.4.1 | ||
custom_lint_builder: ^0.6.4 |
Oops, something went wrong.