I frequently run unit tests from the root directory of the SDK
package. Previous to this CL, that didn't work for the `linter`
package, because the test `validate_sdk_version_map.dart` contained a
hard-coded path that only worked if the test was invoked from the
`pkg/linter` subdirectory.
With this change, the test uses the `packageRoot` getter from the
`analyzer_utilities` package, which locates the SDK's `pkg` directory
using heuristics that work from a variety of different starting
directories, including the root of the SDK repo, anywhere within
`pkg/linter`, and in a Google3 bazel test.
Change-Id: I525ad21cb5228e670dadc98c05de18bddf3912e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339660
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
There are two possible meanings of `?` when it follows an expression:
it could introduce a null-aware index operation (`a?[b]`), or it could
introduce a conditional expression (`a?b:c`). The parser always favors
the second interpretation (see
https://github.com/dart-lang/language/blob/main/accepted/2.12/nnbd/feature-specification.md#null-aware-subscript).
Therefore, if the user wants to use a null-aware index operation in a
context where it is followed by a `:` and then another expression,
parentheses are required around the null-aware index operation, to
prevent the token sequence from being interpreted as a conditional
expression.
This can happen in two circumstances:
- In the "then" part of a conditional expression: `a ? (b?[c]) : d`
- In a map literal key: `{(a?[b]): c}`
The `unnecessary_parenthesis` lint already has a number of exceptions
to handle weirdnesses of the parser; we just need to add one more.
Fixes https://github.com/dart-lang/linter/issues/4812.
Bug: https://github.com/dart-lang/linter/issues/4812
Change-Id: I265103e257d45bfd228972aebba595097b429522
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339480
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This language feature allows the user to declare a static type using
`extension type` syntax, for example:
extension type IdNumber(int i) {
operator <(IdNumber other) => i < other.i;
bool isValid(Some parameters) => ...;
}
This behaves similarly to a "wrapper" class:
class IdNumber {
final int i;
IdNumber(this.i);
operator <(IdNumber other) => i < other.i;
bool isValid(Some parameters) => ...;
}
However, at runtime, no wrapper objects are created; instead, an
instance of the extension type is represented directly by its
"representation type" (`int` in the above example), and methods like
`isValid` are resolved statically. This gives developers an
abstraction mechanism with the advantage of zero runtime performance
cost, since no extra heap space is required, and no extra instructions
are needed to convert between an extension type and its underlying
representation.
The disadvantage of using extension types as an abstraction mechanism
is that since no wrapper objects are created at runtime, the
abstraction can be bypassed using `dynamic`, runtime casts, or by
"laundering" the object through contravariant generic methods like
`List.add` (which are runtime checked in Dart). For example:
main() {
var id = IdNumber(1);
var list1 = <int>[];
List<Object> list2 = list1;
list2.add(id); // OK at compile time because `IdNumber` is a
// subtype of `Object`. OK at runtime because
// at runtime, `IdNumber` and `int` are
// indistinguishable.
int i = list1[0];
print(i);
}
Extension types are expected to be particularly useful for
low-overhead decoding of external data formats (such as JSON), and for
inter-operation with other languages (such as Javascript).
For additional information see the feature specification:
https://github.com/dart-lang/language/blob/main/accepted/future-releases/extension-types/feature-specification.md
Change-Id: I900a3a25dcfc38bfa9c9f9b5b9fa20f362883653
Tested: Standard trybots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335062
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
In this CL we "remove" 3 linter rules, and any subsequently unused quick fixes:
* `always_require_non_null_named_parameters`
* `avoid_returning_null`
* `avoid_returning_null_for_future`
We also delete any code that branched on pre-NNBD libraries; these are
no longer supported.
Change-Id: I3bad7a44de3563e5737919c878170213ad506b82
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336244
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
There is much code in pkg/analyzer/lib/src/lint which is only used by
_tests_ and _tools_ in the linter package. This CL attempts to tidy up
the separation of linter lib code and non-lib code by moving some
files, and moving some source elements, which are only used in tests,
or in tools.
I originally dug into this because I saw `LinterOptions` has a public late field
(dangerous):
`late file_system.ResourceProvider resourceProvider;`
It turns out this field is only initialized in tests and tools, and
then it's read by multiple methods, and it just so happens those
methods are only called during tests or in tools.
Summary of changes:
* Mark LintDriver and DartLinter classes as only used for linter tools
and tests.
* Remove CamelCaseString class.
* Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
* LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove
`resourceProvider`.
* Remove SourceLinter; it was only used in a few `engine_test.dart` tests in
linter, but all uses could be replaced with DartLinter.
* Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of
user entrypoint. The main method is moved to `cli.dart`.
* Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
* analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
and FileGlobFilter are moved to linter's tool/ directory.
* Delete the engine_test.dart tests which only validate basics of
linter's old entrypoint.
This reverts commit d1bc88de8f.
Change-Id: I1063aa72c640ad8ab62f76bf89f665cb8b9952dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334645
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This reverts commit 31eab937f6.
Reason for revert: No way to import "tool/formatter.dart" in g3
Original change's description:
> Improve file structure of linter files.
>
> There is much code in pkg/analyzer/lib/src/lint which is only used by
> _tests_ and _tools_ in the linter package. This CL attempts to tidy up
> the separation of linter lib code and non-lib code by moving some
> files, and moving some source elements, which are only used in tests,
> or in tools.
>
> I originally dug into this because I saw `LinterOptions` has a public late field (dangerous):
>
> `late file_system.ResourceProvider resourceProvider;`
>
> It turns out this field is only initialized in tests and tools, and
> then it's read by multiple methods, and it just so happens those
> methods are only called during tests or in tools.
>
> Summary of changes:
>
> * Mark LintDriver and DartLinter classes as only used for linter tools
> and tests.
> * Remove CamelCaseString class.
> * Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
> * LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove `resourceProvider`.
> * Remove SourceLinter; it was only used in a few `engine_test.dart` tests in linter, but all uses could be replaced with DartLinter.
> * Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of user entrypoint. The main method is moved to `cli.dart`.
> * Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
> * analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
> and FileGlobFilter are moved to linter's tool/ directory.
> * Delete engine_test.dart tests which only validate basics of
> linter's old entrypoint.
>
> Change-Id: Ifc0e70454ee2ac794bc816ef9c77d5519a93eb0a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333128
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
Bug: b/309643288
Change-Id: I69a731ff31507f671277d0395f4ebfbb86d8f607
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334660
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Oleh Prypin <oprypin@google.com>
There is much code in pkg/analyzer/lib/src/lint which is only used by
_tests_ and _tools_ in the linter package. This CL attempts to tidy up
the separation of linter lib code and non-lib code by moving some
files, and moving some source elements, which are only used in tests,
or in tools.
I originally dug into this because I saw `LinterOptions` has a public late field (dangerous):
`late file_system.ResourceProvider resourceProvider;`
It turns out this field is only initialized in tests and tools, and
then it's read by multiple methods, and it just so happens those
methods are only called during tests or in tools.
Summary of changes:
* Mark LintDriver and DartLinter classes as only used for linter tools
and tests.
* Remove CamelCaseString class.
* Mark `DartLinter.lintPubspecSource` as `@visibleForTesting`.
* LinterOptions: mark `enabledLints` and `analysisOptions` final, and remove `resourceProvider`.
* Remove SourceLinter; it was only used in a few `engine_test.dart` tests in linter, but all uses could be replaced with DartLinter.
* Remove linter's `bin/linter.dart`; it is not meant to be used as any sort of user entrypoint. The main method is moved to `cli.dart`.
* Move linter's `lib/src/cli.dart` to `tool/cli.dart`.
* analyzer's top-level function `lintFiles`, classes ErrorWatchingSink
and FileGlobFilter are moved to linter's tool/ directory.
* Delete engine_test.dart tests which only validate basics of
linter's old entrypoint.
Change-Id: Ifc0e70454ee2ac794bc816ef9c77d5519a93eb0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333128
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
* removes stale generated TODO
* fixes test prefixing in the all tests test for cases where tests include `_test`
* adds a file ignore for test prefixes for the all tests test
Change-Id: Ie400e275300683b8f037bb6dae62aa85a3469cff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331201
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>