Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
5e6a1f39
Commit
5e6a1f39
authored
2 years ago
by
AnimeGitB
Committed by
memetrollsXD
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Replace Spotless with simple python lint script
parent
24e9c55a
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.github/workflows/build.yml
+0
-2
0 additions, 2 deletions
.github/workflows/build.yml
.github/workflows/build_lint.yml
+7
-5
7 additions, 5 deletions
.github/workflows/build_lint.yml
build.gradle
+0
-27
0 additions, 27 deletions
build.gradle
format_whitespace.py
+70
-0
70 additions, 0 deletions
format_whitespace.py
with
77 additions
and
34 deletions
.github/workflows/build.yml
+
0
−
2
View file @
5e6a1f39
...
@@ -19,8 +19,6 @@ jobs:
...
@@ -19,8 +19,6 @@ jobs:
steps
:
steps
:
-
name
:
Checkout
-
name
:
Checkout
uses
:
actions/checkout@v3
uses
:
actions/checkout@v3
-
name
:
Fetch LintRatchet
run
:
git fetch origin LintRatchet:LintRatchet
-
name
:
Setup Java
-
name
:
Setup Java
uses
:
actions/setup-java@v3
uses
:
actions/setup-java@v3
with
:
with
:
...
...
This diff is collapsed.
Click to expand it.
.github/workflows/build_lint.yml
+
7
−
5
View file @
5e6a1f39
...
@@ -12,8 +12,12 @@ jobs:
...
@@ -12,8 +12,12 @@ jobs:
steps
:
steps
:
-
name
:
Checkout
-
name
:
Checkout
uses
:
actions/checkout@v3
uses
:
actions/checkout@v3
-
name
:
Fetch LintRatchet
-
name
:
Setup Python
run
:
git fetch origin LintRatchet:LintRatchet
uses
:
actions/setup-python@v4
with
:
python-version
:
'
3.10'
-
name
:
Run Linter
run
:
python format_whitespace.py
-
name
:
Setup Java
-
name
:
Setup Java
uses
:
actions/setup-java@v3
uses
:
actions/setup-java@v3
with
:
with
:
...
@@ -29,8 +33,6 @@ jobs:
...
@@ -29,8 +33,6 @@ jobs:
key
:
${{ runner.os }}-gradle-${{ hashFiles('*.gradle', 'gradle.properties', '**/*.accesswidener') }}
key
:
${{ runner.os }}-gradle-${{ hashFiles('*.gradle', 'gradle.properties', '**/*.accesswidener') }}
restore-keys
:
|
restore-keys
:
|
${{ runner.os }}-gradle-
${{ runner.os }}-gradle-
-
name
:
Run Spotless
run
:
./gradlew spotlessApply
-
name
:
Run Gradle
-
name
:
Run Gradle
run
:
./gradlew && ./gradlew jar
run
:
./gradlew && ./gradlew jar
-
name
:
Upload build
-
name
:
Upload build
...
@@ -38,7 +40,7 @@ jobs:
...
@@ -38,7 +40,7 @@ jobs:
with
:
with
:
name
:
Grasscutter
name
:
Grasscutter
path
:
grasscutter-*.jar
path
:
grasscutter-*.jar
-
name
:
Commit any
Spotless
changes
-
name
:
Commit any
Linter
changes
uses
:
EndBug/add-and-commit@v9
uses
:
EndBug/add-and-commit@v9
with
:
with
:
add
:
'
-u'
add
:
'
-u'
...
...
This diff is collapsed.
Click to expand it.
build.gradle
+
0
−
27
View file @
5e6a1f39
...
@@ -34,9 +34,6 @@ plugins {
...
@@ -34,9 +34,6 @@ plugins {
// Maven
// Maven
id
'maven-publish'
id
'maven-publish'
id
'signing'
id
'signing'
// Spotless formatter
id
"com.diffplug.spotless"
version
"6.8.0"
}
}
compileJava
.
options
.
encoding
=
"UTF-8"
compileJava
.
options
.
encoding
=
"UTF-8"
...
@@ -241,30 +238,6 @@ eclipse {
...
@@ -241,30 +238,6 @@ eclipse {
}
}
}
}
spotless
{
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom
'LintRatchet'
format
'misc'
,
{
// define the files to apply `misc` to
target
'*.gradle'
,
'*.md'
,
'.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace
()
indentWithSpaces
()
// or spaces. Takes an integer argument if you don't like 4
endWithNewline
()
}
java
{
// don't need to set target, it is inferred from java
// define the steps to apply to those files
trimTrailingWhitespace
()
indentWithSpaces
()
// or spaces. Takes an integer argument if you don't like 4
endWithNewline
()
replaceRegex
(
'Force one space between if/etc. and ( or {'
,
'(?<=\\b(?:if|for|while|switch|try|else|catch|finally|synchronized)) *(?=[\\(\\{])'
,
' '
)
replaceRegex
(
'Force one space between ) and {'
,
'\\) *\\{(?!\\})'
,
') {'
)
}
}
signing
{
signing
{
if
(!
version
.
endsWith
(
'-dev'
))
{
if
(!
version
.
endsWith
(
'-dev'
))
{
sign
publishing
.
publications
.
mavenJava
sign
publishing
.
publications
.
mavenJava
...
...
This diff is collapsed.
Click to expand it.
format_whitespace.py
0 → 100644
+
70
−
0
View file @
5e6a1f39
import
re
import
subprocess
UPSTREAM
=
'
https://github.com/Grasscutters/Grasscutter.git
'
RATCHET
=
'
LintRatchet
'
RATCHET_FALLBACK
=
'
8e3deb9
'
re_leading_whitespace
=
re
.
compile
(
r
'
^[ \t]+
'
,
re
.
MULTILINE
)
# Replace with \1.replace('\t', ' ')
re_trailing_whitespace
=
re
.
compile
(
r
'
[ \t]+$
'
,
re
.
MULTILINE
)
# Replace with ''
# Replace 'for (foo){bar' with 'for (foo) {bar'
re_bracket_space
=
re
.
compile
(
r
'
\) *\{(?!\})
'
)
# Replace with ') {'
# Replace 'for(foo)' with 'foo (bar)'
re_keyword_space
=
re
.
compile
(
r
'
(?<=\b)(if|for|while|switch|try|else|catch|finally|synchronized) *(?=[\(\{])
'
)
# Replace with '\1 '
def
get_changed_filelist
():
subprocess
.
run
([
'
git
'
,
'
fetch
'
,
UPSTREAM
,
f
'
{
RATCHET
}
:
{
RATCHET
}
'
])
# Ensure LintRatchet ref is matched to upstream
result
=
subprocess
.
run
([
'
git
'
,
'
diff
'
,
RATCHET
,
'
--name-only
'
],
capture_output
=
True
,
text
=
True
)
if
result
.
returncode
!=
0
:
print
(
f
'
{
RATCHET
}
not found, trying fallback
{
RATCHET_FALLBACK
}
'
)
result
=
subprocess
.
run
([
'
git
'
,
'
diff
'
,
RATCHET_FALLBACK
,
'
--name-only
'
],
capture_output
=
True
,
text
=
True
)
if
result
.
returncode
!=
0
:
print
(
'
Fallback is also missing, aborting.
'
)
exit
(
1
)
return
result
.
stdout
.
strip
().
split
(
'
\n
'
)
def
format_string
(
data
:
str
):
data
=
re_leading_whitespace
.
sub
(
lambda
m
:
m
.
group
(
0
).
replace
(
'
\t
'
,
'
'
),
data
)
data
=
re_trailing_whitespace
.
sub
(
''
,
data
)
data
=
re_bracket_space
.
sub
(
'
) {
'
,
data
)
data
=
re_keyword_space
.
sub
(
r
'
\1
'
,
data
)
if
not
data
.
endswith
(
'
\n
'
):
# Enforce trailing \n
data
=
data
+
'
\n
'
return
data
def
format_file
(
filename
:
str
)
->
bool
:
try
:
with
open
(
filename
,
'
r
'
)
as
file
:
data
=
file
.
read
()
data
=
format_string
(
data
)
with
open
(
filename
,
'
w
'
)
as
file
:
file
.
write
(
data
)
return
True
except
FileNotFoundError
:
print
(
f
'
File not found, probably deleted:
{
filename
}
'
)
return
False
def
main
():
filelist
=
[
f
for
f
in
get_changed_filelist
()
if
f
.
endswith
(
'
.java
'
)]
replaced
=
0
not_found
=
0
if
not
filelist
:
print
(
'
No changed files due for formatting!
'
)
return
print
(
'
Changed files due for formatting:
'
,
filelist
)
for
file
in
filelist
:
if
format_file
(
file
):
replaced
+=
1
else
:
not_found
+=
1
print
(
f
'
Format complete!
{
replaced
}
formatted,
{
not_found
}
missing.
'
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment