-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(neon_lints): add linting rule to avoid using any calls in produc…
…tion Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
173 additions
and
3 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
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:neon_lints/dart.yaml |
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,5 +1,8 @@ | ||
include: package:neon_lints/src/base.yaml | ||
|
||
analyzer: | ||
plugins: | ||
- custom_lint | ||
linter: | ||
rules: | ||
avoid_print: true |
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,16 @@ | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
import 'package:neon_lints/src/amend_model_suffix.dart'; | ||
|
||
/// Registers the neon lints plugin. | ||
/// | ||
/// Do **not** use this dierectly. | ||
/// This method is applied used when enabling the `custom_lint` in the | ||
/// `analysis_options.yaml` file. | ||
PluginBase createPlugin() => _NeonLintsPlugin(); | ||
|
||
class _NeonLintsPlugin extends PluginBase { | ||
@override | ||
List<LintRule> getLintRules(CustomLintConfigs _) => const [ | ||
AvoidDebugPrint(), | ||
]; | ||
} |
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,41 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/error/listener.dart'; | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
|
||
/// Lint rule checking that no print methods from `flutter:framework` are used. | ||
/// | ||
/// Similar to the analyzer rule `avoid_print`. | ||
/// Instead use a a logging framework like `https://pub.dev/packages/logging`. | ||
/// | ||
/// ```dart | ||
/// debugPrint('message'); // lint | ||
/// debugPrintStack(stackTrace: stackTrace); // lint | ||
/// debugPrintSynchronously('message'); // lint | ||
/// debugPrintThrottled('message'); // lint | ||
/// ``` | ||
final class AvoidDebugPrint extends DartLintRule { | ||
/// @nodoc | ||
const AvoidDebugPrint() : super(code: _code); | ||
|
||
static const _code = LintCode( | ||
name: 'avoid_debug_print', | ||
problemMessage: "Don't invoke 'debugPrint' and 'debugPrintStack' in production code.", | ||
correctionMessage: 'Try using a logging framework.', | ||
); | ||
|
||
static const String _debugPrint = 'debugPrint'; | ||
|
||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ErrorReporter reporter, | ||
CustomLintContext context, | ||
) { | ||
context.registry.addInvocationExpression((node) { | ||
final element = node.function; | ||
if (element case Identifier(:final name) when name.startsWith(_debugPrint)) { | ||
reporter.reportErrorForToken(code, node.beginToken); | ||
} | ||
}); | ||
} | ||
} |
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