diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2375096f9..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - extends: [ - 'react-app', - 'prettier/@typescript-eslint', - 'plugin:prettier/recommended', - ], -}; diff --git a/README.md b/README.md index dd8a18721..30af8add1 100644 --- a/README.md +++ b/README.md @@ -340,13 +340,15 @@ Options --fix Fixes fixable errors and warnings --ignore-pattern Ignore a pattern --write-file Write the config file locally + --prettier Use Prettier to lint -h, --help Displays this message Examples - $ tsdx lint src test - $ tsdx lint src test --fix + $ tsdx lint src + $ tsdx lint src --fix $ tsdx lint src test --ignore-pattern test/foobar.ts - $ tsdx lint src test --write-file + $ tsdx lint src --write-file + $ tsdx lint src test --prettier ``` ## Author diff --git a/package.json b/package.json index 2a9ae7636..ec2c23370 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "prepare": "tsc -p tsconfig.json", "build": "tsc -p tsconfig.json", "lint": "yarn build && yarn lint:post-build", - "lint:post-build": "node dist/index.js lint src test --ignore-pattern 'test/tests/lint'", + "lint:post-build": "node dist/index.js lint src test --ignore-pattern 'test/tests/lint' --prettier", "test": "jest --config ./test/jest.config.json" }, "files": [ @@ -50,6 +50,8 @@ "cross-env": "5.2.0", "enquirer": "^2.3.0", "eslint": "^5.16.0", + "eslint-config-prettier": "^4.3.0", + "eslint-plugin-prettier": "^3.1.0", "eslint-config-react-app": "^4.0.1", "eslint-plugin-flowtype": "^2.50.3", "eslint-plugin-import": "^2.17.3", @@ -93,8 +95,6 @@ "@types/react": "^16.8.17", "@types/rollup-plugin-json": "^3.0.2", "@types/rollup-plugin-sourcemaps": "^0.4.2", - "eslint-config-prettier": "^4.3.0", - "eslint-plugin-prettier": "^3.1.0", "husky": "^2.3.0", "prettier": "^1.17.1", "pretty-quick": "^1.10.0", diff --git a/src/createEslintConfig.ts b/src/createEslintConfig.ts index a42f55fd4..f9dcae758 100644 --- a/src/createEslintConfig.ts +++ b/src/createEslintConfig.ts @@ -3,15 +3,23 @@ import path from 'path'; import { CLIEngine } from 'eslint'; interface CreateEslintConfigArgs { + prettier: boolean; rootDir: string; writeFile: boolean; } export function createEslintConfig({ + prettier, rootDir, writeFile, }: CreateEslintConfigArgs): CLIEngine.Options['baseConfig'] { + const baseExtends = ['react-app']; const config = { - extends: ['react-app'], + extends: prettier + ? baseExtends.concat([ + 'prettier/@typescript-eslint', + 'plugin:prettier/recommended', + ]) + : baseExtends, }; if (writeFile) { diff --git a/src/index.ts b/src/index.ts index 26f67014c..abfa9807f 100755 --- a/src/index.ts +++ b/src/index.ts @@ -406,9 +406,12 @@ prog .example('lint src test --ignore-pattern test/foobar.ts') .option('--write-file', 'Write the config file locally') .example('lint src test --write-file') + .option('--prettier', 'Use Prettier to lint') + .example('lint src test --prettier') .action( async (opts: { fix: boolean; + prettier: boolean; 'ignore-pattern': string; 'write-file': boolean; _: string[]; @@ -419,6 +422,7 @@ prog ignorePattern: opts['ignore-pattern'], baseConfig: { ...createEslintConfig({ + prettier: opts.prettier, rootDir: paths.appRoot, writeFile: opts['write-file'], }), diff --git a/test/tests/lint/file-with-lint-errors.ts b/test/tests/lint/file-with-lint-errors.ts index 3e8e21f8f..77a8e933b 100644 --- a/test/tests/lint/file-with-lint-errors.ts +++ b/test/tests/lint/file-with-lint-errors.ts @@ -1,4 +1 @@ -export const foo = ( ) => -!! ('bar') -; - +export const foo () => !!'bar'; diff --git a/test/tests/lint/file-with-prettier-lint-errors.ts b/test/tests/lint/file-with-prettier-lint-errors.ts new file mode 100644 index 000000000..ec7429dd2 --- /dev/null +++ b/test/tests/lint/file-with-prettier-lint-errors.ts @@ -0,0 +1,5 @@ +export const foo = ( ) => +!! ('bar') +; + + \ No newline at end of file diff --git a/test/tests/lint/react-file-with-lint-errors.tsx b/test/tests/lint/react-file-with-lint-errors.tsx index f5e7449b5..41f3538e6 100644 --- a/test/tests/lint/react-file-with-lint-errors.tsx +++ b/test/tests/lint/react-file-with-lint-errors.tsx @@ -1,6 +1,6 @@ import React from 'react'; -export const Foobar = (props: any ) => { +export const Foobar (props: any ) => { return