Commit Graph

27 Commits

Author SHA1 Message Date
FMorschel 83eb816e51 [linter] Adds new switch_on_type lint
Fixes: https://github.com/dart-lang/sdk/issues/59546
Change-Id: Ib78714e03c1487376c961214910d10c24ec9f8ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413600
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
2025-05-16 16:00:54 -07:00
Sam Rawlins b6508124a4 linter: add unnecessary_unawaited lint rule
Work towards https://github.com/dart-lang/sdk/issues/46218

Change-Id: I0c6953463d053205cc1110f554578e6b85eac0db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426240
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-05-02 14:36:20 -07:00
Chloe Stefantsova 4b9ed5eb4f [lint] Add lint for using null-aware elements
The lint suggests rewriting explicit null-checks, such as:

* [if (x != null) x]
* {if (x case var key?) key: "value"}

The suggested rewrite is to use the null-aware marker '?':

* [?x]
* {?x: "value"}

Change-Id: If37d096755fee14b3d9dee0f730d3302176ad0f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411685
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-02-25 09:10:58 -08:00
pq 2dc6d31f8a [lint] new lint: unnecessary_ignore
See: https://github.com/dart-lang/sdk/issues/35234

As a follow-up, I'll update the reporting to skip generated files.


Change-Id: Icddcdf59269d82576eefd810671a3e992f2bcca5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404480
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2025-01-15 10:21:42 -08:00
Konstantin Shcheglov 609f2f95b1 Linter. Issue 59814. Report unnecessary_async.
Bug: https://github.com/dart-lang/sdk/issues/59814
Change-Id: Iebf90315e7c443e00ea84c380f85ac6c84bc86c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403320
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2025-01-08 13:24:49 -08:00
pq 259bf2445d [lint] unnecessary_underscores core implementation
(TODO: follow-up w/ improved documentation.)

Bug: https://github.com/dart-lang/sdk/issues/56595
Change-Id: I000ccf9012c659d7fbc942d8bc0fafce87dafc5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403201
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-01-06 16:20:18 -08:00
Sam Rawlins 4d2e8a9ce7 lint rules: Add strict_top_level_inference rule
Closes https://github.com/dart-lang/sdk/issues/59562

Change-Id: Ibf7ab6343d15ed328a366960b45cad4242528588
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400164
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-12-16 08:46:34 -08:00
Erik Ernst 7b71ed17b2 Introduce the lint unsafe_variance
This CL implements a new lint, `unsafe_variance`. This lint emits a
warning whenever an instance member declaration has a signature where
a type variable declared by the enclosing class/mixin/enum occurs in
a non-covariant position in the return type (including the type of
an instance variable).

Issues: https://github.com/dart-lang/linter/issues/4111, with goals related to https://github.com/dart-lang/language/issues/296 and https://github.com/dart-lang/language/issues/524.

Change-Id: I1352d71d61fece03a432ccf0d98825a69e3a457f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384700
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2024-11-15 09:28:52 +00:00
Sam Rawlins cb5c73e06f linter: Remove unsafe_html rule
Fixes https://github.com/dart-lang/linter/issues/5001

Change-Id: I972ea8f9fafda88b6a4836ab92107cebe8a6ad4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391303
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-11-08 18:31:59 +00:00
Erik Ernst e6f81dfbc3 Add new lints {omit_,specify_non}obvious_property_types
See https://github.com/dart-lang/linter/issues/5101 for some background information.

Change-Id: I51b6988f08585b7b4863ae8858d44de831615177
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2024-10-21 08:08:37 +00:00
Parker Lougheed e032779a86 [linter] Deprecate package_api_docs lint
The lint hasn't been functional for a long time. Rather than try to fix it and start introducing a lot of warnings on packages that include it, let's deprecate it and prepare for removal. Keeping it around in its current state results in the analyzer not meeting the expectations of developers that include the rule, potentially even causing misconceptions that an element isn't public when it is.

A replacement, with a new name, can be introduced in the future if there is the desire and time to implement it.

Bug: https://github.com/dart-lang/linter/issues/5107
Change-Id: Ied113e4c98be2253cb938277cfd6ea1c96bcac4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389585
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-10-16 21:13:27 +00:00
Samuel Rawlins dac5fa8567 Revert "lint rule: Remove the avoid_null_checks_in_equality_operators rule"
This reverts commit 5572900016.

Reason for revert: broke the assorted_layout_widgets customer tests.

Original change's description:
> lint rule: Remove the avoid_null_checks_in_equality_operators rule
>
> Fixes https://github.com/dart-lang/linter/issues/5063
>
> Change-Id: I85a3c9e1a568d55ce1e21d0f1fee4ce1c83292f4
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389300
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>

Change-Id: I3ff1448088f4d5163dc66f6e181a97302c4d137a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390300
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2024-10-15 20:25:28 +00:00
Sam Rawlins 5572900016 lint rule: Remove the avoid_null_checks_in_equality_operators rule
Fixes https://github.com/dart-lang/linter/issues/5063

Change-Id: I85a3c9e1a568d55ce1e21d0f1fee4ce1c83292f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389300
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-10-14 20:57:04 +00:00
Erik Ernst 46cff10fc7 Add lint avoid_futureor_void
This CL adds support for a new lint, `avoid_futureor_void`, that reports on every occurrence of the type `FutureOr<void>` in a covariant or invariant position. More details can be found at https://github.com/dart-lang/linter/issues/4622.

Change-Id: I1b86e04921d1fb0b3661be091ea1f4ad72089e8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382403
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 10:49:48 +00:00
Erik Ernst 5b7c600d8b Implement the lint 'specify_nonobvious_local_variable_types'
This lint is the complement of 'omit_obvious_local_variable_types'
in that it flags every declaration that does _not_ specify the type
of a local variable, when it has an initializing expression whose type
is not obvious (defined as in 'omit_obvious_local_variable_types').

Change-Id: If80a961e47fed0412d0ea0bac5ac010e26fea7bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379160
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-08-13 09:43:49 +00:00
Sam Rawlins b946c47ec9 new lint rule: use_truncating_division
Fixes https://github.com/dart-lang/linter/issues/3930

This allows us to remove (softly) the DIVISION_OPTIMIZATION HintCode,
which was not deemed a good candidate for a Warning.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Iac48c94687d0b6b32c971e9f366ccb96adf34429
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378543
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-02 22:31:19 +00:00
Erik Ernst 002bcd022b Add lint omit_obvious_local_variable_types
This CL adds an implementation of a lint named
'omit_obvious_local_variable_types' which is a variant of
'omit_local_variable_types' that only flags type annotations
of local variables when the static type of the initializing
expression is obvious, as defined in
https://github.com/dart-lang/linter/issues/3480.

Change-Id: I7e9b5adde5839ad8f9dfa88833da82d7bc1b65de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374601
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-07-16 15:36:40 +00:00
Sam Rawlins 607b3f5ddb linter: new rule for documenting ignore comments
In order to land this new rule, I add a new `IgnoredElement` subclass,
`IgnoredDiagnosticComment`, for any trailing comment text. This seems
like a pretty clean implementation. The text and offset are not used,
but it seems like it would be inconsistent to not offer them.

I also make a few IgnoreInfo fields private that are unused outside
the library.

Fixes https://github.com/dart-lang/linter/issues/4860

Change-Id: Id6f949a317929dae8833e404d4c9f3c8e4f7bc90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365488
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-05-10 14:24:58 +00:00
Srujan Gaddam b0a34dbccb [linter/analyzer] Add lint for runtime type tests of JS types
Closes https://github.com/dart-lang/linter/issues/4841

Adds a lint to verify and report whether an is check or a cast
may result in platform-inconsistent behavior. In order to do so,
adds necessary additions to canBeSubtypeOf and extends the mock
SDK. Also adds this to the list of default rules.

Change-Id: I7f235ee698419d9f253cc96f08322bedca271825
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361722
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-05-08 20:57:59 +00:00
Kallen Tu cd4b418628 [linter] Add unintended_html_in_doc_comment lint.
This CL adds a lint that reports when a user uses a pair of angled brackets which are not in a code block, nor a code span, and is not an autolink.

Updated the `rules.json` for the new lint as well.

Bug: https://github.com/dart-lang/linter/issues/4793
Change-Id: I1ca762b5e62678b8c6fba60206f3465154696b6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359900
Reviewed-by: Morgan :) <davidmorgan@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-02 21:09:51 +00:00
pq 200e6d987d rename to unnecessary_library_name
As noted by Lasse, we're not really consistent and the singular is more "correct".

See: https://github.com/dart-lang/sdk/commit/71456592d0268238ac0f8a5c7d3fd8bf2c096752#r140033857


Change-Id: I55afeab8c42d9f20999e263682f71d54a2302ea5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358682
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-03-20 19:28:52 +00:00
pq 71456592d0 + unnecessary_library_names
Fixes: https://github.com/dart-lang/linter/issues/3882

(I'll follow-up with a quick-fix.)

Change-Id: Ice88bfb59a16163b003ce94c73e057d2fd968a9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358561
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-03-20 16:54:59 +00:00
Kallen Tu 7e12dddee6 Add 'missing_code_block_language_in_doc_comment' lint.
This CL adds a lint that warns you if you are missing a language info string after the first code block fence.

This should replace Dartdoc's in-house `missingCodeBlockLanguage` warning.

Bug: https://github.com/dart-lang/linter/issues/4904
Change-Id: Ie7279a8a0c041de6937ab0841c4a207b16064307
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356282
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-03-11 18:25:40 +00:00
Brian Wilkerson 8356cfeb8f Deprecate avoid_unstable_final_fields
Change-Id: I1d47dfcef9d910875833823aaf304f2945bb3254
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340285
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-12-07 21:55:18 +00:00
Erik Ernst cdc16e7d3d Create lint PR 3578 as Gerrit CL
This CL transfers the changes made by
https://github.com/dart-lang/linter/pull/3578
to Gerrit.

Change-Id: Ib1eae56d2112e25bcf9916abf27b05bd3de15735
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326342
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-12 10:09:10 +00:00
pq d1b6ea9f4d +annotate_redeclares
Fixes: https://github.com/dart-lang/linter/issues/4747

Change-Id: I7bf3e83dbe279f5b1a03dc5e5806c7c0fe3e3486
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-09-18 02:41:29 +00:00
William Hesse 86c86d638a Add linter repository to sdk, preserving its commit history
Added using git-subtree command git subtree add -P pkg/linter linter/main

Bug: https://github.com/dart-lang/linter/issues/4411
2023-08-23 14:05:34 +02:00