Skip to content

Commit 3f37053

Browse files
committed
eslint: adding readme (common and plugin-gradle)
1 parent 1d164d3 commit 3f37053

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
### Added
14+
* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433))
15+
1316
### Changes
1417
* Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409))
1518
* We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml`

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}}
6969
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7070
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
7171
lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
72+
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7273
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7374
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
7475
lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
@@ -113,6 +114,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}}
113114
| [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
114115
| [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
115116
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
117+
| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
116118
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
117119
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
118120
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433))
68
### Fixed
79
* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215))
810

plugin-gradle/README.md

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
6969
- [FreshMark](#freshmark) aka markdown
7070
- [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
7171
- [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
72-
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier))
72+
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [eslint](#eslint--typescript-))
73+
- [Javascript](#javascript) ([prettier](#prettier), [eslint](#eslint--javascript-))
7374
- [JSON](#json)
7475
- Multiple languages
7576
- [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection))
@@ -576,6 +577,7 @@ spotless {
576577
577578
tsfmt() // has its own section below
578579
prettier() // has its own section below
580+
eslint() // has its own section below
579581
580582
licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile
581583
// note the '(import|const|...' argument - this is a regex which identifies the top
@@ -608,6 +610,122 @@ spotless {
608610
609611
For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt.
610612
613+
### eslint (Typescript)
614+
615+
[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:*
616+
The auto-discovery of config files (up the file tree) will not work when using eslint within spotless,
617+
hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline.
618+
619+
The configuration is very similar to the [eslint (Javascript)](#eslint--javascript-) configuration. It differs in supported
620+
styleguides and the requirement for a tsconfigFile.
621+
622+
```gradle
623+
spotless {
624+
typescript {
625+
eslint('8.30.0') // version is optional
626+
eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use
627+
628+
eslint()
629+
// optional: use a popular eslint styleguide for typescript
630+
.styleGuide('standard-with-typescript') // or 'xo-typescript'
631+
// configuration is mandatory. Provide inline config or a config file.
632+
// a) inline-configuration
633+
.configJs('''
634+
{
635+
env: {
636+
browser: true,
637+
es2021: true
638+
},
639+
extends: 'standard-with-typescript',
640+
overrides: [
641+
],
642+
parserOptions: {
643+
ecmaVersion: 'latest',
644+
sourceType: 'module',
645+
project: './tsconfig.json',
646+
},
647+
rules: {
648+
}
649+
}
650+
''')
651+
// b) config file
652+
.configFile('.eslintrc.js')
653+
// recommended: provide a tsconfig.json - especially when using the styleguides
654+
.tsconfigFile('tsconfig.json')
655+
}
656+
}
657+
```
658+
659+
**Prerequisite: eslint requires a working NodeJS version**
660+
661+
For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint.
662+
663+
## Javascript
664+
665+
- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java)
666+
667+
```gradle
668+
spotless {
669+
javascript {
670+
target 'src/**/*.js' // you have to set the target manually
671+
672+
prettier() // has its own section below
673+
eslint() // has its own section below
674+
675+
licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile
676+
}
677+
}
678+
```
679+
680+
### eslint (Javascript)
681+
682+
[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:*
683+
The auto-discovery of config files (up the file tree) will not work when using eslint within spotless,
684+
hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline.
685+
686+
The configuration is very similar to the [eslint (Typescript)](#eslint--typescript-) configuration. It differs in supported
687+
styleguides and no requirement for a tsconfig (of course).
688+
689+
```gradle
690+
691+
```gradle
692+
spotless {
693+
javascript {
694+
eslint('8.30.0') // version is optional
695+
eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use
696+
697+
eslint()
698+
// optional: use a popular eslint styleguide for javascript
699+
.styleGuide('standard') // or 'airbnb', 'google', 'xo'
700+
// configuration is mandatory. Provide inline config or a config file.
701+
// a) inline-configuration
702+
.configJs('''
703+
{
704+
env: {
705+
browser: true,
706+
es2021: true
707+
},
708+
extends: 'standard',
709+
overrides: [
710+
],
711+
parserOptions: {
712+
ecmaVersion: 'latest',
713+
sourceType: 'module'
714+
},
715+
rules: {
716+
}
717+
}
718+
''')
719+
// b) config file
720+
.configFile('.eslintrc.js')
721+
}
722+
}
723+
```
724+
725+
**Prerequisite: eslint requires a working NodeJS version**
726+
727+
For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint.
728+
611729
## JSON
612730
613731
- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java)

0 commit comments

Comments
 (0)