Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
75127a80
Unverified
Commit
75127a80
authored
Jan 25, 2022
by
Jesús S Guerrero
Committed by
GitHub
Jan 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] support files in flutter analyze #96231 (#97021)
parent
2978629e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
21 deletions
+75
-21
analyze_once.dart
packages/flutter_tools/lib/src/commands/analyze_once.dart
+15
-17
analyze_once_test.dart
...utter_tools/test/integration.shard/analyze_once_test.dart
+60
-4
No files found.
packages/flutter_tools/lib/src/commands/analyze_once.dart
View file @
75127a80
...
@@ -48,17 +48,15 @@ class AnalyzeOnce extends AnalyzeBase {
...
@@ -48,17 +48,15 @@ class AnalyzeOnce extends AnalyzeBase {
final
String
currentDirectory
=
final
String
currentDirectory
=
(
workingDirectory
??
fileSystem
.
currentDirectory
).
path
;
(
workingDirectory
??
fileSystem
.
currentDirectory
).
path
;
// find directories from argResults.rest
// find directories
or files
from argResults.rest
final
Set
<
String
>
directorie
s
=
Set
<
String
>.
of
(
argResults
.
rest
final
Set
<
String
>
item
s
=
Set
<
String
>.
of
(
argResults
.
rest
.
map
<
String
>((
String
path
)
=>
fileSystem
.
path
.
canonicalize
(
path
)));
.
map
<
String
>((
String
path
)
=>
fileSystem
.
path
.
canonicalize
(
path
)));
if
(
directorie
s
.
isNotEmpty
)
{
if
(
item
s
.
isNotEmpty
)
{
for
(
final
String
directory
in
directorie
s
)
{
for
(
final
String
item
in
item
s
)
{
final
FileSystemEntityType
type
=
fileSystem
.
typeSync
(
directory
);
final
FileSystemEntityType
type
=
fileSystem
.
typeSync
(
item
);
if
(
type
==
FileSystemEntityType
.
notFound
)
{
if
(
type
==
FileSystemEntityType
.
notFound
)
{
throwToolExit
(
"'
$directory
' does not exist"
);
throwToolExit
(
"'
$item
' does not exist"
);
}
else
if
(
type
!=
FileSystemEntityType
.
directory
)
{
throwToolExit
(
"'
$directory
' is not a directory"
);
}
}
}
}
}
}
...
@@ -67,17 +65,17 @@ class AnalyzeOnce extends AnalyzeBase {
...
@@ -67,17 +65,17 @@ class AnalyzeOnce extends AnalyzeBase {
// check for conflicting dependencies
// check for conflicting dependencies
final
PackageDependencyTracker
dependencies
=
PackageDependencyTracker
();
final
PackageDependencyTracker
dependencies
=
PackageDependencyTracker
();
dependencies
.
checkForConflictingDependencies
(
repoPackages
,
dependencies
);
dependencies
.
checkForConflictingDependencies
(
repoPackages
,
dependencies
);
directorie
s
.
addAll
(
repoRoots
);
item
s
.
addAll
(
repoRoots
);
if
(
argResults
.
wasParsed
(
'current-package'
)
&&
(
argResults
[
'current-package'
]
as
bool
))
{
if
(
argResults
.
wasParsed
(
'current-package'
)
&&
(
argResults
[
'current-package'
]
as
bool
))
{
directorie
s
.
add
(
currentDirectory
);
item
s
.
add
(
currentDirectory
);
}
}
}
else
{
}
else
{
if
(
argResults
[
'current-package'
]
as
bool
)
{
if
(
(
argResults
[
'current-package'
]
as
bool
)
&&
items
.
isEmpty
)
{
directorie
s
.
add
(
currentDirectory
);
item
s
.
add
(
currentDirectory
);
}
}
}
}
if
(
directorie
s
.
isEmpty
)
{
if
(
item
s
.
isEmpty
)
{
throwToolExit
(
'Nothing to analyze.'
,
exitCode:
0
);
throwToolExit
(
'Nothing to analyze.'
,
exitCode:
0
);
}
}
...
@@ -86,7 +84,7 @@ class AnalyzeOnce extends AnalyzeBase {
...
@@ -86,7 +84,7 @@ class AnalyzeOnce extends AnalyzeBase {
final
AnalysisServer
server
=
AnalysisServer
(
final
AnalysisServer
server
=
AnalysisServer
(
sdkPath
,
sdkPath
,
directorie
s
.
toList
(),
item
s
.
toList
(),
fileSystem:
fileSystem
,
fileSystem:
fileSystem
,
platform:
platform
,
platform:
platform
,
logger:
logger
,
logger:
logger
,
...
@@ -133,9 +131,9 @@ class AnalyzeOnce extends AnalyzeBase {
...
@@ -133,9 +131,9 @@ class AnalyzeOnce extends AnalyzeBase {
// collect results
// collect results
timer
=
Stopwatch
()..
start
();
timer
=
Stopwatch
()..
start
();
final
String
message
=
directorie
s
.
length
>
1
final
String
message
=
item
s
.
length
>
1
?
'
${
directories.length}
${directories.length == 1 ? 'directory' : 'directorie
s'}
'
?
'
${
items.length}
${items.length == 1 ? 'item' : 'item
s'}
'
:
fileSystem
.
path
.
basename
(
directorie
s
.
first
);
:
fileSystem
.
path
.
basename
(
item
s
.
first
);
progress
=
argResults
[
'preamble'
]
==
true
progress
=
argResults
[
'preamble'
]
==
true
?
logger
.
startProgress
(
?
logger
.
startProgress
(
'Analyzing
$message
...'
,
'Analyzing
$message
...'
,
...
...
packages/flutter_tools/test/integration.shard/analyze_once_test.dart
View file @
75127a80
...
@@ -13,6 +13,7 @@ void main() {
...
@@ -13,6 +13,7 @@ void main() {
late
Directory
tempDir
;
late
Directory
tempDir
;
late
String
projectPath
;
late
String
projectPath
;
late
File
libMain
;
late
File
libMain
;
late
File
errorFile
;
Future
<
void
>
runCommand
({
Future
<
void
>
runCommand
({
List
<
String
>
arguments
=
const
<
String
>[],
List
<
String
>
arguments
=
const
<
String
>[],
...
@@ -79,6 +80,7 @@ void main() {
...
@@ -79,6 +80,7 @@ void main() {
setUp
(()
{
setUp
(()
{
tempDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'flutter_analyze_once_test_1.'
).
absolute
;
tempDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'flutter_analyze_once_test_1.'
).
absolute
;
projectPath
=
fileSystem
.
path
.
join
(
tempDir
.
path
,
'flutter_project'
);
projectPath
=
fileSystem
.
path
.
join
(
tempDir
.
path
,
'flutter_project'
);
final
String
projectWithErrors
=
fileSystem
.
path
.
join
(
tempDir
.
path
,
'flutter_project_errors'
);
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectPath
,
'pubspec.yaml'
))
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectPath
,
'pubspec.yaml'
))
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
pubspecYamlSrc
);
..
writeAsStringSync
(
pubspecYamlSrc
);
...
@@ -86,6 +88,9 @@ void main() {
...
@@ -86,6 +88,9 @@ void main() {
libMain
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectPath
,
'lib'
,
'main.dart'
))
libMain
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectPath
,
'lib'
,
'main.dart'
))
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
mainDartSrc
);
..
writeAsStringSync
(
mainDartSrc
);
errorFile
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectWithErrors
,
'other'
,
'error.dart'
))
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
r""
"import 'package:flutter/material.dart"""
);
});
});
tearDown
(()
{
tearDown
(()
{
...
@@ -100,12 +105,63 @@ void main() {
...
@@ -100,12 +105,63 @@ void main() {
);
);
});
});
// testWithoutContext a specific file outside the current directory
testWithoutContext
(
'passing one file works'
,
()
async
{
testWithoutContext
(
'passing one file throws'
,
()
async
{
await
runCommand
(
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
libMain
.
path
],
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
libMain
.
path
],
exitMessageContains:
'is not a directory'
,
statusTextContains:
<
String
>[
'No issues found!'
]
exitCode:
1
,
);
});
testWithoutContext
(
'passing one file with errors are detected'
,
()
async
{
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
errorFile
.
path
],
statusTextContains:
<
String
>[
'Analyzing error.dart'
,
"error
$analyzerSeparator
Target of URI doesn't exist"
,
"error
$analyzerSeparator
Expected to find ';'"
,
'error
$analyzerSeparator
Unterminated string literal'
],
exitMessageContains:
'3 issues found'
,
exitCode:
1
);
});
testWithoutContext
(
'passing more than one file with errors'
,
()
async
{
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
libMain
.
path
,
errorFile
.
path
],
statusTextContains:
<
String
>[
'Analyzing 2 items'
,
"error
$analyzerSeparator
Target of URI doesn't exist"
,
"error
$analyzerSeparator
Expected to find ';'"
,
'error
$analyzerSeparator
Unterminated string literal'
],
exitMessageContains:
'3 issues found'
,
exitCode:
1
);
});
testWithoutContext
(
'passing more than one file success'
,
()
async
{
final
File
secondFile
=
fileSystem
.
file
(
fileSystem
.
path
.
join
(
projectPath
,
'lib'
,
'second.dart'
))
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
''
);
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
libMain
.
path
,
secondFile
.
path
],
statusTextContains:
<
String
>[
'No issues found!'
]
);
});
testWithoutContext
(
'mixing directory and files success'
,
()
async
{
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
libMain
.
path
,
projectPath
],
statusTextContains:
<
String
>[
'No issues found!'
]
);
});
testWithoutContext
(
'file not found'
,
()
async
{
await
runCommand
(
arguments:
<
String
>[
'analyze'
,
'--no-pub'
,
'not_found.abc'
],
exitMessageContains:
"not_found.abc' does not exist"
,
exitCode:
1
);
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment