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

Introduce code formatting + git hooks #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: Continuous Testing

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- uses: gradle/gradle-build-action@v2
- run: gradle wrapper
- run: ./gradlew test
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: "11"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to 11 for the newest version of spotless, but source and target compilation is still set to 8

distribution: "temurin"
- uses: gradle/gradle-build-action@v2
- run: gradle wrapper
- run: ./gradlew check
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: local
hooks:
- id: spotless
name: spotless
language: system
entry: ./gradlew spotlessApply
pass_filenames: false
always_run: true
- id: git-diff
name: git-diff
language: system
entry: git --no-pager diff --color --exit-code
always_run: true
4 changes: 4 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins:
- prettier-plugin-java
- prettier-plugin-properties
tabWidth: 4
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGELOG

**v0.1.0:**
- Initial implementation of [the spec](https://github.com/sqids/sqids-spec)
- Packaging & cleanup

- Initial implementation of [the spec](https://github.com/sqids/sqids-spec)
- Packaging & cleanup
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# [Sqids Java](https://sqids.org/java)

[Sqids](https://sqids.org/java) (*pronounced "squids"*) is a small library that lets you **generate unique IDs from
[Sqids](https://sqids.org/java) (_pronounced "squids"_) is a small library that lets you **generate unique IDs from
numbers**. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker
database lookups.

Features:

- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers
- **Quick decoding** - easily decode IDs back into numbers
- **Unique IDs** - generate unique IDs by shuffling the alphabet once
- **ID padding** - provide minimum length to make IDs more uniform
- **URL safe** - auto-generated IDs do not contain common profanity
- **Randomized output** - Sequential input provides nonconsecutive IDs
- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)
- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers
- **Quick decoding** - easily decode IDs back into numbers
- **Unique IDs** - generate unique IDs by shuffling the alphabet once
- **ID padding** - provide minimum length to make IDs more uniform
- **URL safe** - auto-generated IDs do not contain common profanity
- **Randomized output** - Sequential input provides nonconsecutive IDs
- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)

## 🧰 Use-cases

Good for:

- Generating IDs for public URLs (eg: link shortening)
- Generating IDs for internal systems (eg: event tracking)
- Decoding for quicker database lookups (eg: by primary keys)
- Generating IDs for public URLs (eg: link shortening)
- Generating IDs for internal systems (eg: event tracking)
- Decoding for quicker database lookups (eg: by primary keys)

Not good for:

- Sensitive data (this is not an encryption library)
- User IDs (can be decoded revealing user count)

- Sensitive data (this is not an encryption library)
- User IDs (can be decoded revealing user count)

## System Requirements
Java 8 or higher is required.

Java 8 or higher is required.

## 🚀 Getting started

Download and Import Sqids via:

```java
import org.sqids.Sqids;

```

## 👩‍💻 Examples
Expand All @@ -55,7 +55,7 @@ List<Long> numbers=sqids.decode(id); // [1, 2, 3]
> important to your design that IDs are canonical, you have to manually re-encode decoded numbers and check that the
> generated ID matches.

Enforce a *minimum* length for IDs:
Enforce a _minimum_ length for IDs:

```java
Sqids sqids=Sqids.builder()
Expand Down Expand Up @@ -87,4 +87,4 @@ List<Long> numbers=sqids.decode(id); // [1, 2, 3]

## 📝 License

[MIT](LICENSE)
[MIT](LICENSE)
51 changes: 40 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugins {
id 'com.diffplug.spotless' version '6.23.1'
id 'com.github.node-gradle.node' version '7.0.1'
id 'java-library'
id 'maven-publish'
id 'signing'
Expand All @@ -7,7 +9,7 @@ plugins {
group = 'org.sqids'
version = '0.1.0-SNAPSHOT'

String rootArtifactiId = 'sqids'
String rootArtifactId = 'sqids'
String projectUrl = 'https://sqids.org/java'

repositories {
Expand All @@ -17,7 +19,7 @@ repositories {
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
Expand All @@ -34,20 +36,19 @@ java {

publishing {
publications {

mavenJava(MavenPublication) {
groupId = group
artifactId = rootArtifactiId
artifactId = rootArtifactId
version = version
from components.java
pom {
name = 'Sqids'
description = 'Generate short YouTube-looking IDs from numbers.'
url = projectUrl
properties = [
"parent.groupId": "org.sonatype.oss",
"parent.artifactId": "oss-parent",
"parent.version": "7"
'parent.groupId': 'org.sonatype.oss',
'parent.artifactId': 'oss-parent',
'parent.version': '7'
]
licenses {
license {
Expand All @@ -72,12 +73,12 @@ publishing {
}
repositories {
maven {
def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
String releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
String snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username "${System.getenv("SONATYPE_USERNAME")}"
password "${System.getenv("SONATYPE_PASSWORD")}"
username System.getenv('SONATYPE_USERNAME')
password System.getenv('SONATYPE_PASSWORD')
}
}
}
Expand All @@ -86,3 +87,31 @@ publishing {
sign publishing.publications.mavenJava
}
}

node {
download = true
}

String nodeSetup = 'nodeSetup'
String npmSetup = 'npmSetup'

spotless {
format 'prettier', {
target '**/*.java', '**/*.properties', '**/*.md', '**/*.yml', '**/*.yaml'
targetExclude 'bin/**/*', 'gradle/**/*'

boolean isWindows = System.getProperty('os.name').toLowerCase().contains('windows')
String nodeExec = isWindows ? '/node.exe' : '/bin/node'
String npmExec = isWindows ? '/npm.cmd' : '/bin/npm'

prettier(['prettier': '3.1.0', 'prettier-plugin-java': '2.2.0', 'prettier-plugin-properties': '0.3.0'])
.npmInstallCache()
.npmExecutable("${tasks.named(npmSetup).get().npmDir.get()}${npmExec}")
.nodeExecutable("${tasks.named(nodeSetup).get().nodeDir.get()}${nodeExec}")
.configFile('.prettierrc.yaml')
}
}

tasks.named('spotlessPrettier').configure { task ->
task.dependsOn(nodeSetup, npmSetup)
}
Loading