Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
atools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leo
atools
Commits
ace9d949
Commit
ace9d949
authored
May 27, 2019
by
Leo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
superfluous-cd-builddir improvements
parent
7eec8f64
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
2 deletions
+74
-2
NEWS
NEWS
+5
-0
apkbuild-lint
apkbuild-lint
+7
-2
tests/apkbuild-lint.bats
tests/apkbuild-lint.bats
+62
-0
No files found.
NEWS
View file @
ace9d949
CHANGES with 12:
- superfluous-cd-builddir now detects variations of cd "$builddir" such as with brackets
without quotes and any in between
CHANGES with 11.2:
- make duplicate and upper package detection remove tab chars ('\t') before sorting
...
...
apkbuild-lint
View file @
ace9d949
...
...
@@ -150,6 +150,9 @@ superfluous_cd_builddir() {
# if the previous line had a 'cd "$builddir"' statement
prevcd
=
0
# If it is the first cd of the program
firstcd
=
1
# Use newline as our IFS delimiter, so we can iterate over lines with
# the for construct, since the while loop will create a subshell that
# prevents the value of the prevcd variable from being propagated
...
...
@@ -161,14 +164,16 @@ superfluous_cd_builddir() {
linenum
=
"
$(
printf
"%s
\\
n"
"
$line
"
|
awk
'{ print $1 }'
)
"
statement
=
"
$(
printf
"%s
\\
n"
"
$line
"
|
awk
'{ $1="" ; print $0 }'
)
"
[
-z
"
$statement
"
]
&&
continue
if
echo
"
$statement
"
|
grep
-
q
'cd "$builddir"\($\| \)'
;
then
if
[
"
$prevcd
"
-eq
1
]
||
[
"
$cdscount
"
-eq
1
]
;
then
if
echo
"
$statement
"
|
grep
-
E
-q
'cd ["]?\$[{]?builddir["}]?+($| )'
;
then
if
[
"
$prevcd
"
-eq
1
]
||
[
"
$cdscount
"
-eq
1
]
||
[
"
$firstcd
"
-eq
1
]
;
then
printf
"%s:%s: cd
\"\$
builddir
\"
can be removed in phase '%s'
\\
n"
"
$apkbuild
"
"
$linenum
"
"
$phase
"
fi
prevcd
=
1
else
prevcd
=
0
fi
# Can be set to 0 in the first loop and the re-set it to 0 in any next loops
firstcd
=
0
done
IFS
=
"
$OLDIFS
"
}
...
...
tests/apkbuild-lint.bats
View file @
ace9d949
...
...
@@ -60,6 +60,68 @@ is_travis() {
[[ $status -eq 0 ]]
}
@test 'cd \"\$builddir\" with brackets should be detected' {
cat <<-"EOF" >$apkbuild
pkgname=a
pkgver=1
build() {
cd "${builddir}"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "builddir.*can be removed"
}
@test 'cd \"\$builddir\" with brackets and no quotes should be detected' {
cat <<-"EOF" >$apkbuild
pkgname=a
pkgver=1
build() {
cd ${builddir}
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "builddir.*can be removed"
}
@test 'cd \"\$builddir\" without quotes should be detected' {
cat <<-"EOF" >$apkbuild
pkgname=a
pkgver=1
build() {
cd $builddir
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "builddir.*can be removed"
}
@test 'cd \"\$builddir\" should be highlighted if it is also the first' {
cat <<-"EOF" >$apkbuild
pkgname=a
pkgver=1
build() {
cd $builddir
cd ${builddir}
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "builddir.*can be removed"
assert_match "${lines[1]}" "builddir.*can be removed"
}
@test 'unnecessary || return 1 can be removed' {
cat <<-"EOF" >$apkbuild
pkgname=a
...
...
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