-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New linters/formatter for dart (#650)
Adds definitions for `format`, `fix`, and `analyze`. From a brief audit, users may prefer to remove individual subcommands but the full set is the best default.
- Loading branch information
1 parent
9fd55bd
commit 28be597
Showing
8 changed files
with
212 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from "path"; | ||
import { customLinterCheckTest } from "tests"; | ||
import { TrunkLintDriver } from "tests/driver"; | ||
import { TEST_DATA } from "tests/utils"; | ||
|
||
const preCheck = (driver: TrunkLintDriver) => { | ||
driver.moveFile(path.join(TEST_DATA, "pubspec.yaml"), "pubspec.yaml"); | ||
driver.moveFile(path.join(TEST_DATA, "analysis_options.yaml"), "analysis_options.yaml"); | ||
}; | ||
|
||
customLinterCheckTest({ | ||
linterName: "dart", | ||
args: `${TEST_DATA} -y`, | ||
testName: "basic", | ||
preCheck, | ||
pathsToSnapshot: [path.join(TEST_DATA, "basic.in.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,62 @@ | ||
version: 0.1 | ||
downloads: | ||
- name: dart | ||
downloads: | ||
- os: | ||
linux: linux | ||
macos: macos | ||
windows: windows | ||
cpu: | ||
x86_64: x64 | ||
arm_64: arm64 | ||
url: https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-${os}-${cpu}-release.zip | ||
strip_components: 1 | ||
tools: | ||
definitions: | ||
- name: dart | ||
download: dart | ||
known_good_version: 3.2.6 | ||
shims: [dart, dartaotruntime] | ||
environment: | ||
- name: PATH | ||
list: ["${tool}/bin"] | ||
lint: | ||
files: | ||
- name: dart | ||
extensions: [dart] | ||
definitions: | ||
- name: dart | ||
main_tool: dart | ||
files: [dart] | ||
known_good_version: 3.2.6 | ||
suggest_if: never | ||
affects_cache: | ||
- analysis_options.yaml | ||
- pubspec.yaml | ||
commands: | ||
- name: format | ||
output: rewrite | ||
run: dart format ${target} | ||
batch: true | ||
in_place: true | ||
formatter: true | ||
success_codes: [0] | ||
- name: fix | ||
# Some analyze results are autofixable, others are not. | ||
output: rewrite | ||
run: dart fix --apply ${target} | ||
batch: true | ||
fix_prompt: Quick fix available | ||
fix_verb: fix | ||
in_place: true | ||
success_codes: [0] | ||
- name: analyze | ||
output: regex | ||
# The output only includes the filename so in order to use a relative path we need to run from parent. | ||
run_from: ${parent} | ||
parse_regex: | ||
\s*(?P<severity>.*) - (?P<path>.*):(?P<line>\d+):(?P<col>\d+) - (?P<message>.*) - | ||
(?P<code>.*) | ||
run: dart analyze --no-fatal-warnings ${target} | ||
success_codes: [0, 3] | ||
batch: 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,3 @@ | ||
linter: | ||
rules: | ||
- use_super_parameters |
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,14 @@ | ||
library; | ||
import 'dart:io'; | ||
class Vector2d { | ||
final double x, y; | ||
Vector2d(this.x, this.y); | ||
} | ||
class Vector3d extends Vector2d { | ||
final double z; | ||
Vector3d(final double x, final double y, this.z) : super(x, y); | ||
} | ||
|
||
void main() { | ||
expect(find.text(''), empty); | ||
} |
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,92 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter dart test basic 1`] = ` | ||
{ | ||
"issues": [ | ||
{ | ||
"code": "undefined_identifier", | ||
"column": "10", | ||
"file": "test_data/basic.in.dart", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "14", | ||
"linter": "dart", | ||
"message": "Undefined name 'find'. Try correcting the name to one that is defined, or defining the name.", | ||
"targetType": "dart", | ||
}, | ||
{ | ||
"code": "undefined_identifier", | ||
"column": "25", | ||
"file": "test_data/basic.in.dart", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "14", | ||
"linter": "dart", | ||
"message": "Undefined name 'empty'. Try correcting the name to one that is defined, or defining the name.", | ||
"targetType": "dart", | ||
}, | ||
{ | ||
"code": "undefined_function", | ||
"column": "3", | ||
"file": "test_data/basic.in.dart", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "14", | ||
"linter": "dart", | ||
"message": "The function 'expect' isn't defined. Try importing the library that defines 'expect', correcting the name to the name of an existing function, or defining a function named 'expect'.", | ||
"targetType": "dart", | ||
}, | ||
], | ||
"lintActions": [ | ||
{ | ||
"command": "analyze", | ||
"fileGroupName": "dart", | ||
"linter": "dart", | ||
"paths": [ | ||
"test_data/basic.in.dart", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "analyze", | ||
"fileGroupName": "dart", | ||
"linter": "dart", | ||
"paths": [ | ||
"test_data/basic.in.dart", | ||
], | ||
"upstream": true, | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "fix", | ||
"fileGroupName": "dart", | ||
"linter": "dart", | ||
"paths": [ | ||
"test_data/basic.in.dart", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "fix", | ||
"fileGroupName": "dart", | ||
"linter": "dart", | ||
"paths": [ | ||
"test_data/basic.in.dart", | ||
], | ||
"upstream": true, | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "format", | ||
"fileGroupName": "dart", | ||
"linter": "dart", | ||
"paths": [ | ||
"test_data/basic.in.dart", | ||
], | ||
"verb": "TRUNK_VERB_FMT", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [], | ||
} | ||
`; |
20 changes: 20 additions & 0 deletions
20
linters/dart/test_data/dart_v3.2.6_test_data.basic.in.dart.check.shot
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter dart test basic 1`] = ` | ||
"library; | ||
|
||
class Vector2d { | ||
final double x, y; | ||
Vector2d(this.x, this.y); | ||
} | ||
|
||
class Vector3d extends Vector2d { | ||
final double z; | ||
Vector3d(super.x, super.y, this.z); | ||
} | ||
|
||
void main() { | ||
expect(find.text(''), empty); | ||
} | ||
" | ||
`; |
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,2 @@ | ||
environment: | ||
sdk: ">=2.17.0 <4.0.0" |