diff --git a/.all-contributorsrc b/.all-contributorsrc
index 114bd78..afe6265 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -170,6 +170,16 @@
"doc",
"tool"
]
+ },
+ {
+ "login": "morhetz",
+ "name": "Pavel Pertsev",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/554231?v=4",
+ "profile": "http://morhetz.com",
+ "contributions": [
+ "code",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index bd5d6c4..afb3d23 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ CLI for [`prettier-eslint`][prettier-eslint]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
-[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors)
+[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
@@ -95,6 +95,7 @@ Options:
[boolean] [default: false]
--eslint-path The path to the eslint module to use
[default: "./node_modules/eslint"]
+ --eslint-config-path Path to the eslint config to use for eslint --fix
--prettier-path The path to the prettier module to use
[default: "./node_modules/prettier"]
--ignore pattern(s) you wish to ignore (can be used multiple
@@ -177,6 +178,11 @@ echo "var foo = 'bar'" | prettier-eslint --stdin
Forwarded as the `eslintPath` option to `prettier-eslint`
+#### --eslint-config-path
+
+Resolve eslint config file, parse and forward config object as the `eslintConfig` option to
+`prettier-eslint`
+
#### --prettier-path
Forwarded as the `prettierPath` option to `prettier-eslint`
@@ -237,7 +243,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
Kent C. Dodds](https://kentcdodds.com)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Code") [๐](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Documentation") [๐](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Tests") | [
Adam Harris](https://github.com/aharris88)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Code") [๐](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Documentation") [๐](#review-aharris88 "Reviewed Pull Requests") | [
Eric McCormick](https://ericmccormick.io)
[๐](#review-edm00se "Reviewed Pull Requests") | [
Joel Sequeira](https://github.com/joelseq)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [
Frank Taillandier](https://frank.taillandier.me)
| [
Adam Stankiewicz](http://sheerun.net)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [
Stephen John Sorensen](http://www.stephenjohnsorensen.com/)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Gandem](https://github.com/Gandem)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [
Matteo Ronchi](https://github.com/cef62)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [
Benoรฎt Zugmeyer](https://github.com/BenoitZugmeyer)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [
Charlike Mike Reagent](https://i.am.charlike.online)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") | [
Dion Dirza](https://github.com/diondirza)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Adiondirza "Bug reports") | [
mrm007](https://github.com/mrm007)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amrm007 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=mrm007 "Code") | [
Jack Franklin](http://www.jackfranklin.co.uk)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=jackfranklin "Code") |
-| [
Ryan Zimmerman](http://www.ryanzim.com)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=RyanZim "Documentation") | [
Paolo Moretti](http://stackoverflow.com/users/63011)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amoretti "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Tests") | [
bySabi Files](https://github.com/bySabi)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=bySabi "Documentation") [๐ง](#tool-bySabi "Tools") |
+| [
Ryan Zimmerman](http://www.ryanzim.com)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=RyanZim "Documentation") | [
Paolo Moretti](http://stackoverflow.com/users/63011)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amoretti "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Tests") | [
bySabi Files](https://github.com/bySabi)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=bySabi "Documentation") [๐ง](#tool-bySabi "Tools") | [
Pavel Pertsev](http://morhetz.com)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=morhetz "Code") |
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
diff --git a/__mocks__/fs.js b/__mocks__/fs.js
index a67d2ba..144d5ad 100644
--- a/__mocks__/fs.js
+++ b/__mocks__/fs.js
@@ -6,6 +6,10 @@ const writeFile = jest.fn((filePath, contents, callback) => {
})
const readFileSync = jest.fn(filePath => {
+ if (filePath.indexOf('.eslintrc') !== -1) {
+ return '{ "rules": { "semi": "error" } }'
+ }
+
if (filePath.indexOf('eslintignore')) {
return '*ignored*\n**/ignored/**\n'
} else {
@@ -13,4 +17,8 @@ const readFileSync = jest.fn(filePath => {
}
})
-module.exports = {readFile, writeFile, readFileSync}
+const readdirSync = jest.fn(() => {
+ return []
+})
+
+module.exports = {readFile, writeFile, readFileSync, readdirSync}
diff --git a/package.json b/package.json
index 9087dd8..88a50c9 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
"camelcase-keys": "^4.1.0",
"chalk": "^1.1.3",
"common-tags": "^1.4.0",
+ "eslint": "^3.19.0",
"find-up": "^2.1.0",
"get-stdin": "^5.0.1",
"glob": "^7.1.1",
@@ -51,7 +52,6 @@
"codecov": "^2.1.0",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
- "eslint": "^3.19.0",
"eslint-config-kentcdodds": "^12.2.1",
"husky": "^0.13.3",
"jest-cli": "^19.0.2",
diff --git a/src/format-files.js b/src/format-files.js
index 5bc8075..e6377eb 100644
--- a/src/format-files.js
+++ b/src/format-files.js
@@ -11,6 +11,7 @@ import findUp from 'find-up'
import memoize from 'lodash.memoize'
import indentString from 'indent-string'
import getLogger from 'loglevel-colored-level-prefix'
+import ConfigFile from 'eslint/lib/config/config-file'
import * as messages from './messages'
const LINE_SEPERATOR_REGEX = /(\r|\n|\r\n)/
@@ -36,6 +37,7 @@ function formatFilesFromArgv({
prettierPath,
ignore: ignoreGlobs = [],
eslintIgnore: applyEslintIgnore = true,
+ eslintConfigPath,
prettierLast,
...prettierOptions
}) {
@@ -47,6 +49,11 @@ function formatFilesFromArgv({
prettierLast,
prettierOptions,
}
+
+ if (eslintConfigPath) {
+ prettierESLintOptions.eslintConfig = ConfigFile.load(eslintConfigPath)
+ }
+
const cliOptions = {write, listDifferent}
if (stdin) {
return formatStdin(prettierESLintOptions)
diff --git a/src/format-files.test.js b/src/format-files.test.js
index 6dbb342..06c95f0 100644
--- a/src/format-files.test.js
+++ b/src/format-files.test.js
@@ -280,3 +280,13 @@ describe('listDifferent', () => {
expect(process.exitCode).toBe(0)
})
})
+
+describe('eslintConfigPath', () => {
+ test('will use eslintrc', async () => {
+ await formatFiles({
+ _: ['src/**/1*.js'],
+ eslintConfigPath: '.eslintrc',
+ })
+ expect(process.exitCode).toBe(0)
+ })
+})
diff --git a/src/parser.js b/src/parser.js
index bcc32cd..880cdaa 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -53,6 +53,11 @@ const parser = yargs
describe: 'The path to the eslint module to use',
coerce: coercePath,
},
+ // allow `--eslint-config-path` and `--eslintConfigPath`
+ 'eslint-config-path': {
+ default: undefined,
+ describe: 'Path to the eslint config to use for eslint --fix',
+ },
// allow `--prettier-path` and `--prettierPath`
'prettier-path': {
describe: 'The path to the prettier module to use',
@@ -150,14 +155,6 @@ const parser = yargs
},
// TODO: support range-start and range-end
// would require changes in prettier-eslint
- // TODO: if we allow people to to specify a config path,
- // we need to read that somehow. These can come invarious
- // formats and we'd have to work out `extends` somehow as well.
- // I don't know whether ESLint exposes a way to do this...
- // Contributions welcome!
- // eslintConfigPath: {
- // describe: 'Path to the eslint config to use for eslint --fix',
- // },
})
.strict()