Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new experimental rule no-empty-file #1963

Closed
wants to merge 84 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7393cb8
Add new rule don't allow empty files
ao0000 Apr 17, 2023
57608a7
Set to standard rule provider
ao0000 Apr 17, 2023
8e5da5a
Refactor editorconfig property description
ao0000 Apr 17, 2023
f091560
Add test for no empty file rule
ao0000 Apr 18, 2023
b1f2f55
Add to support editorconfig settings
ao0000 Apr 18, 2023
cfa3169
Add test for supporting editorconfig
ao0000 Apr 18, 2023
20bae7f
Fix default setting and remove rule experimental
ao0000 Apr 18, 2023
3239077
Update documents about no empty file rule
ao0000 Apr 18, 2023
4b4c0fc
Modify to experimental rule
ao0000 Apr 22, 2023
34cb7a3
Update CHANGELOG.md
ao0000 Apr 22, 2023
7c69606
Merge branch 'master' into 1074-empty-file
ao0000 Apr 22, 2023
91e4d9c
Fix CHANGELOG.md
ao0000 Apr 22, 2023
de73411
Remove no empty files section in docs
ao0000 Apr 22, 2023
349c2e4
Change to alphabetical order
ao0000 Apr 22, 2023
152fec3
Refactor NoEmptyFileRule
ao0000 Apr 23, 2023
775fa47
Fix to enable no_empty_file rule on default to reduce .editorconfig
ao0000 Apr 23, 2023
2ce9573
Fix NoEmptyFileRuleTest
ao0000 Apr 23, 2023
3632568
Add non-empty kotlin file version test
ao0000 Apr 23, 2023
1ad2609
Format
ao0000 Apr 23, 2023
13403b4
Add empty file case for package or import statements only
ao0000 Apr 26, 2023
14614c1
Move comment to unreleased added section in CHANGELOG.md
ao0000 Apr 29, 2023
3fa16cd
Add test case about only package and only import statement
ao0000 Apr 29, 2023
497fcf6
Delete editorconfig property
ao0000 Apr 30, 2023
504209e
Add test case about only import statement
ao0000 Apr 30, 2023
e359879
Disable test case related on Windows OS file system
ao0000 May 1, 2023
0143e19
Merge branch 'master' into 1074-empty-file
ao0000 May 1, 2023
f22e522
Revert "Disable test case related on Windows OS file system"
ao0000 May 1, 2023
2ef3a34
Fix lint error to use file name
ao0000 May 1, 2023
078921c
Merge branch 'master' into 1074-empty-file
ao0000 May 4, 2023
b69bdc5
Fix CHANGELOG.md
ao0000 May 4, 2023
f408c88
Handle parameter `--code-style=android_studio` in Ktlint CLI identica…
paul-dingemans May 5, 2023
9214183
Prevent nullpointer exception (NPE) if class without body is followed…
paul-dingemans May 5, 2023
9f9328f
Add comment why the configuration cache is disabled (#1992)
paul-dingemans May 5, 2023
b30515d
Print absolute path of file in lint violations (#1988)
paul-dingemans May 5, 2023
33a888f
Prevent nullpointer exception (NPE) if or operator at start of line i…
paul-dingemans May 5, 2023
6e25045
Allow to 'unset' the `.editorconfig` property `ktlint_function_signat…
paul-dingemans May 5, 2023
fc16aa0
Restrict indentation of closing quotes to `ktlint_official` code styl…
paul-dingemans May 7, 2023
7ba9ed0
Fix indentation of multiline parameter list in function literal (#1997)
paul-dingemans May 7, 2023
6500181
Clean up logging dependencies (#1999)
paul-dingemans May 7, 2023
bc39250
Fix interchanged sample code; rule no-empty-first-line-in-method-bloc…
avinash3699 May 9, 2023
9256b8e
Fix directory traversal for patterns outside workdirectory (#2004)
paul-dingemans May 9, 2023
930d263
Extract rule `no-single-line-block-comment` from `comment-wrapping` r…
paul-dingemans May 9, 2023
321abad
Fix typos (#2007)
avinash3699 May 10, 2023
cd1c78f
Release to SDKMan when publishing a release (#1978)
eygraber May 10, 2023
7d38d3d
Configure versioned documentation (#2008)
paul-dingemans May 10, 2023
0733b86
Rename Github workflows and restrict publish-snapshot-build to code f…
paul-dingemans May 11, 2023
7428f84
Documentation how to (#2012)
paul-dingemans May 11, 2023
0600f93
Move Baseline to ktlint-cli-reporter-baseline (#2013)
paul-dingemans May 11, 2023
a28e8b9
Prepare release 0.49.1 (#2015)
paul-dingemans May 12, 2023
432f609
Fix for SDKMan config, and temporarily disabling (#2019)
shashachu May 12, 2023
b81bb05
Fix announce script (#2020)
paul-dingemans May 12, 2023
709c6ce
Fix reference to compare 0.49.0 with 0.49.1 release (#2021)
paul-dingemans May 12, 2023
7884b62
Updated refs to latest (0.49.1) release (#2022)
paul-dingemans May 12, 2023
48ffc6e
Prepare 0.49.2-SNAPSHOT (#2023)
paul-dingemans May 12, 2023
18a7b40
Add new rule don't allow empty files
ao0000 Apr 17, 2023
ec92ae5
Set to standard rule provider
ao0000 Apr 17, 2023
cebcb5b
Refactor editorconfig property description
ao0000 Apr 17, 2023
b819b01
Add test for no empty file rule
ao0000 Apr 18, 2023
cc6efa5
Add to support editorconfig settings
ao0000 Apr 18, 2023
a4c5fcd
Add test for supporting editorconfig
ao0000 Apr 18, 2023
42a26f1
Fix default setting and remove rule experimental
ao0000 Apr 18, 2023
55fd7c0
Update documents about no empty file rule
ao0000 Apr 18, 2023
5cf3364
Modify to experimental rule
ao0000 Apr 22, 2023
d52d449
Update CHANGELOG.md
ao0000 Apr 22, 2023
0fff6ac
Fix CHANGELOG.md
ao0000 Apr 22, 2023
96216c5
Remove no empty files section in docs
ao0000 Apr 22, 2023
ffa90dd
Change to alphabetical order
ao0000 Apr 22, 2023
5e56473
Refactor NoEmptyFileRule
ao0000 Apr 23, 2023
acf2497
Fix to enable no_empty_file rule on default to reduce .editorconfig
ao0000 Apr 23, 2023
6544a12
Fix NoEmptyFileRuleTest
ao0000 Apr 23, 2023
a09b082
Add non-empty kotlin file version test
ao0000 Apr 23, 2023
4ff5861
Format
ao0000 Apr 23, 2023
0797c77
Add empty file case for package or import statements only
ao0000 Apr 26, 2023
79bc58b
Move comment to unreleased added section in CHANGELOG.md
ao0000 Apr 29, 2023
3aaeba2
Add test case about only package and only import statement
ao0000 Apr 29, 2023
b195e95
Delete editorconfig property
ao0000 Apr 30, 2023
3e7f64f
Add test case about only import statement
ao0000 Apr 30, 2023
4338af8
Disable test case related on Windows OS file system
ao0000 May 1, 2023
c8dcd0d
Revert "Disable test case related on Windows OS file system"
ao0000 May 1, 2023
c487e6d
Fix lint error to use file name
ao0000 May 1, 2023
ed040e4
Fix CHANGELOG.md
ao0000 May 4, 2023
5d446a4
Update changelog and experimental documentation
paul-dingemans May 14, 2023
0b957e4
Merge remote-tracking branch 'github-desktop-ao0000/1074-empty-file' …
paul-dingemans May 14, 2023
d62ff7e
Refactor:
paul-dingemans May 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor NoEmptyFileRule
ao0000 authored and paul-dingemans committed May 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5e56473971d91c8ed8fb94962a2dd1daba10d709
Original file line number Diff line number Diff line change
@@ -25,25 +25,16 @@ public class NoEmptyFileRule :
if (noEmptyFile) {
node
.takeIf { it.elementType == ElementType.FILE }
?.takeIf { it.textLength == TEXT_LENGTH_EMPTY_FILE_CONTAINS }
?.takeIf { it.text.isBlank() }
?.let {
val filePath = it.psi.containingFile.virtualFile.name
val fileName =
filePath
.replace("\\", "/") // Ensure compatibility with Windows OS
.substringAfterLast("/")
emit(
0,
"File `$fileName` should not be empty",
false,
)
.replace("\\", "/") // Ensure compatibility with Windows OS
emit(0, "File `$filePath` should not be empty", false)
}
}
}

public companion object {
private const val TEXT_LENGTH_EMPTY_FILE_CONTAINS: Int = 0

public val NO_EMPTY_FILE_PROPERTY: EditorConfigProperty<Boolean> =
EditorConfigProperty(
type =