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
Show file tree
Hide file tree
Changes from all commits
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
95 changes: 73 additions & 22 deletions .announce
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash -e

# project.version
if [ "$VERSION" == "" ]; then exit 1; fi
if [ "$VERSION" == "" ]; then
echo "VERSION has not been set"
exit 1;
fi

if [ "$1" = "-y" ]; then
AUTOACCEPT=true
Expand All @@ -23,43 +26,91 @@ fi

echo "Announcing $PREVIOUS_VERSION -> $VERSION"

COMMIT_MESSAGE="Updated refs to latest ($VERSION) release"
DOCUMENTATION_DIR="documentation"
RELEASE_DOCS_DIR="${DOCUMENTATION_DIR}/release-latest"
SNAPSHOT_DOCS_DIR="${DOCUMENTATION_DIR}/snapshot"

if [ "$(git status --porcelain=v1 docs/install/cli.md docs/install/integrations.md)" != "" ]; then
echo "ERROR: To proceed, cli.md and integrations.md must not contain uncommitted changes"
if [ "$(git status --porcelain=v1 $DOCUMENTATION)" != "" ]; then
echo "ERROR: To proceed, the current branch must not contain uncommitted changes in directory '${DOCUMENTATION_DIR}'"
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "revert changes? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git checkout docs/install/cli.md docs/install/integrations.md; fi
read -p "revert changes? (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git checkout ${DOCUMENTATION_DIR}
else
exit 1
fi
else
echo "Reverting changes to cli.md and integrations.md"
git checkout docs/install/cli.md docs/install/integrations.md
echo "Reverting changes in directory '${DOCUMENTATION_DIR}'"
git checkout ${DOCUMENTATION_DIR}
fi
fi

escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; }
#escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; }

# update Docs

sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/cli.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/integrations.md
git --no-pager diff docs/install/cli.md docs/install/integrations.md

# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
fi
# Make a separate branch because master branch is protected

BRANCH="$VERSION-update-refs"

if [ "$(git show-ref refs/heads/$BRANCH)" != "" ]; then
echo "ERROR: Branch $BRANCH already exists."
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Delete local branch? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git branch -D $BRANCH; fi
read -p "Delete local branch? (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
else
git branch -D $BRANCH
fi
else
echo "Deleting local branch $BRANCH"
git branch -D $BRANCH
fi
# Checkout local master branch so that changes to this script can be tested without pushing the script to the remote branch
git checkout --track master -b $BRANCH
else
git checkout --track origin/master -b $BRANCH
fi

# Make a separate branch because master branch is protected
git checkout --track origin/master -b $BRANCH && git commit -m "$COMMIT_MESSAGE" docs/install/cli.md docs/install/integrations.md && git push origin $BRANCH
# update version number in snapshot docs

echo "Updating version numbers in (snapshot) installation documentation"
# On local machine (OSX) Use "sed -i '' ..." instead of "sed -i -e ..." as the latter creates a new file.
# On Github Action workflow the "sed -i -e ..." is required as otherwise it results in failure
# "can't read s/0.49.0/0.49.1/g: No such file or directory"
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/cli.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/integrations.md
git --no-pager diff ${DOCUMENTATION_DIR}

# ask for user confirmation before committing
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Accept changes (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi

# Replace release documentation with current snapshot documentation.

echo "Replace release documentation with current snapshot documentation"
# Support removal of files which still exists in release docs but which are no longer present in snapshot docs
rm -rf ${RELEASE_DOCS_DIR}/docs/
cp -r ${SNAPSHOT_DOCS_DIR}/docs/ ${RELEASE_DOCS_DIR}/docs/
# Note that directory "${SNAPSHOT_DOCS_DIR}/overrides/" should not replace "${RELEASE_DOCS_DIR}/overrides/"
cp -r ${SNAPSHOT_DOCS_DIR}/mkdocs.yml ${RELEASE_DOCS_DIR}
# Add files which previously did not yet exists in the release docs but were present in the snapshot docs
git add --all
# Display sorted list of files changed but do not show contents as that could be a lot
git status --porcelain=v1 documentation | sort

# Commit and push changes
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Commit and push changes (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
git commit -m "Updated refs to latest ($VERSION) release"
git push origin $BRANCH
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: PR Build
name: Build pull request

on:
push:
branches:
- master
branches: ['master']
paths: ['**/*.kt', '**/*.kts', '**/*.properties', '**/*.toml']
pull_request:
workflow_dispatch:

Expand Down Expand Up @@ -38,4 +38,3 @@ jobs:
run: ./gradlew build ktlintCheck --no-configuration-cache
- name: Build with dev Kotlin version
run: ./gradlew -PkotlinDev build ktlintCheck --no-configuration-cache

16 changes: 0 additions & 16 deletions .github/workflows/gradle-docs-publish.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Validate Gradle Wrapper"

on: [ push, pull_request ]

jobs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Release
name: Publish release build

on :
push :
Expand Down Expand Up @@ -35,6 +35,20 @@ jobs:
if: ${{ success() }}
uses : ffurrer2/extract-release-notes@v1

- name: Get version
id: get_version
if: ${{ success() }}
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: Create zip for dependency managers
if: ${{ success() }}
run: |
cd ktlint-cli/build/run
# Doing this for Homebrew and https://github.com/sdkman/sdkman-cli/wiki/Well-formed-SDK-archives
mkdir -p ktlint-${{ env.version }}/bin
cp ktlint ktlint-${{ env.version }}/bin
zip -rm ktlint-${{ env.version }}.zip ktlint-${{ env.version }}

- name : Create release
id: github_release
if: ${{ success() }}
Expand All @@ -48,26 +62,28 @@ jobs:
env :
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}

- name: Get version
id: get_version
if: ${{ success() }}
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: Bump Homebrew Formula
if: ${{ success() }}
uses: mislav/bump-homebrew-formula-action@v2
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TOKEN }}
with:
formula-name: ktlint
download-url: https://github.com/pinterest/ktlint/releases/download/${{ env.version }}/ktlint
download-url: https://github.com/pinterest/ktlint/releases/download/${{ env.version }}/ktlint-${{ env.version }}.zip

- name: Release to sdkman
if: false
env:
SDKMAN_KEY: ${{ secrets.SDKMAN_KEY }}
SDKMAN_TOKEN: ${{ secrets.SDKMAN_TOKEN }}
SDKMAN_VERSION: ${{ env.version }}
run: ./gradlew :ktlint-cli:sdkMajorRelease

- name: Announce Release
- name: Update Release documentation
if: ${{ success() }}
run: |
git config user.email "<>" |
git config user.name "Ktlint Release Workflow" |
./.announce -y
env:
VERSION: ${{ env.version }}

41 changes: 41 additions & 0 deletions .github/workflows/publish-release-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish release documentation

on:
push:
branches: ['master']
paths: ['documentation/release-latest/**']

jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository == 'pinterest/ktlint'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all commits/branches
- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install mkdocs and mike
run: pip install mkdocs-material mike

- name: Config git
run: |
git config user.email "[email protected]"
git config user.name "Ktlint Release Workflow"

- name: Get last released version
run: echo "version=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV

- name: Deploy release docs
run: |
echo "Deploy release docs to version ${{ env.version }}"
cd documentation/release-latest
# Release docs are versioned so that user can use relevant docs for the ktlint version they use
mike deploy --push --update-aliases ${{ env.version }} latest

- name: Update default release docs
run: |
cd documentation/release-latest
mike set-default --push latest
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Snapshot Publish
name: Publish snapshot build

on:
push:
branches: [ master ]
paths: ['**/*.kt', '**/*.kts', '**/*.properties', '**/*.toml']

env:
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publish-snapshot-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish snapshot documentation

on:
push:
branches: ['master']
paths: ['documentation/snapshot/**']

jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository == 'pinterest/ktlint'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all commits/branches
- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install mkdocs and mike
run: pip install mkdocs-material mike

- name: Config git
run: |
git config user.email "[email protected]"
git config user.name "Ktlint Release Workflow"

- run: |
cd documentation/snapshot
# The dev-snapshot version has no release number as the version will only be tagged when an official release is build
# This also prevents that multiple snapshot versions of the documentation will be published in parallel
mike deploy --push dev-snapshot
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,39 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## Unreleased

### Added
* Add new experimental rule `no-empty-file` for all code styles. Kotlin file may not be empty.

* Add new experimental rule `no-empty-file` for all code styles. A kotlin (script) file may not be empty ([#1074](https://github.com/pinterest/ktlint/issues/1074))

### Removed

### Fixed

### Changed

## [0.49.1] - 2023-05-12

### Added

### Removed

### Fixed
* Store path of file containing a lint violation relative to the location of the baseline file itself ([#1962](https://github.com/pinterest/ktlint/issues/1962))
* Print absolute path of file in lint violations when flag "--relative" is not specified in Ktlint CLI ([#1963](https://github.com/pinterest/ktlint/issues/1963))
* Handle parameter `--code-style=android_studio` in Ktlint CLI identical to deprecated parameter `--android` ([#1982](https://github.com/pinterest/ktlint/issues/1982))
* Prevent nullpointer exception (NPE) if class without body is followed by multiple blank lines until end of file `no-consecutive-blank-lines` ([#1987](https://github.com/pinterest/ktlint/issues/1987))
* Allow to 'unset' the `.editorconfig` property `ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than` when using `ktlint_official` code style `function-signature` ([#1977](https://github.com/pinterest/ktlint/issues/1977))
* Prevent nullpointer exception (NPE) if or operator at start of line is followed by dot qualified expression `indent` ([#1993](https://github.com/pinterest/ktlint/issues/1993))
* Fix indentation of multiline parameter list in function literal `indent` ([#1976](https://github.com/pinterest/ktlint/issues/1976))
* Restrict indentation of closing quotes to `ktlint_official` code style to keep formatting of other code styles consistent with `0.48.x` and before `indent` ([#1971](https://github.com/pinterest/ktlint/issues/1971))
* Extract rule `no-single-line-block-comment` from `comment-wrapping` rule. The `no-single-line-block-comment` rule is added as experimental rule to the `ktlint_official` code style, but it can be enabled explicitly for the other code styles as well. ([#1980](https://github.com/pinterest/ktlint/issues/1980))
* Clean-up unwanted logging dependencies ([#1998](https://github.com/pinterest/ktlint/issues/1998))
* Fix directory traversal for patterns referring to paths outside of current working directory or any of it child directories ([#2002](https://github.com/pinterest/ktlint/issues/2002))

### Changed
* Separated Baseline functionality out of `ktlint-cli` into separate `ktlint-baseline` module for API consumers

* Moved class `Baseline` from `ktlint-cli` to `ktlint-cli-reporter-baseline` so that Baseline functionality is reusable for API Consumers.

## [0.49.0] - 2023-04-21

Expand Down Expand Up @@ -1862,6 +1886,7 @@ set in `[*{kt,kts}]` section).

## 0.1.0 - 2016-07-27

[0.49.1]: https://github.com/pinterest/ktlint/compare/0.49.0...0.49.1
[0.49.0]: https://github.com/pinterest/ktlint/compare/0.48.2...0.49.0
[0.48.2]: https://github.com/pinterest/ktlint/compare/0.48.1...0.48.2
[0.48.1]: https://github.com/pinterest/ktlint/compare/0.48.0...0.48.1
Expand Down
Loading