diff --git a/.editorconfig b/.editorconfig index 16ebd2b..712fc7a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,11 +7,11 @@ root = true [*] -# change these settings to your own preference +# General Settings: change these as needed indent_style = space indent_size = 2 -# we recommend you to keep these unchanged +# keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true @@ -23,3 +23,12 @@ trim_trailing_whitespace = false [{package,bower}.json] indent_style = space indent_size = 2 + +# Force JavaScript settings to match ESLint rules +[*.js] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc.js b/.eslintrc.js index bbaad8b..7c7ea56 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,34 +1 @@ -const _ = { merge: require('lodash.merge') } -const prettierConfig = _.merge( - {}, - require('./lib/base').rules['prettier/prettier'][1] -) - -module.exports = { - extends: [ - './lib/prettier-standard.js' - ], - overrides: [ - { - files: [ - 'lib/**/*.js' - ], - rules:{ - /* Force double quotes to make it easier to copy the source JavaScript into - * JSON files - */ - quotes: ['error', 'double'], - 'prettier/prettier': [ - 'error', - _.merge( - {}, - prettierConfig, - { - 'singleQuote': false - } - ) - ] - } - } - ] -} +module.exports = require('./prettier-file') diff --git a/.npmignore b/.npmignore index 34a1ccf..abeaa0e 100644 --- a/.npmignore +++ b/.npmignore @@ -59,6 +59,8 @@ # ------------------------------------------------------------------------------ .editorconfig .eslintrc.js +.gitattributes +.gitignore # ============================================================================== diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..8dd7ecc --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,2 @@ +// Use the same configuration that we expose to users for our own formatting. +module.exports = require('./prettierrc.js') diff --git a/README.markdown b/README.markdown index e91f4ea..3a2a017 100644 --- a/README.markdown +++ b/README.markdown @@ -1,13 +1,19 @@ # eslint-config-prettier-standard -An ESLint [shareable config](http://eslint.org/docs/developer-guide/shareable-configs) for projects using **Prettier** and **JavaScript Standard Style** as ESLint rules. +An ESLint [shareable config](http://eslint.org/docs/developer-guide/shareable-configs) +for projects using **Prettier** and **JavaScript Standard Style** as ESLint +rules. ## Installation -### One Line Installation +These instructions assume that you've already installed ESLint +(`npm install --save-dev eslint`). + +### Two Line Installation ``` -npm install --save-dev eslint-config-prettier-standard eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard eslint-plugin-prettier prettier +npm install --save-dev eslint-config-prettier eslint-config-prettier-standard eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-standard prettier-config-standard +npm install --save-dev --save-exact prettier ``` ### Line By Line Installation @@ -15,10 +21,9 @@ npm install --save-dev eslint-config-prettier-standard eslint eslint-config-pret Install the peer dependencies: ``` -npm install --save-dev eslint -npm install --save-dev eslint-config-prettier -npm install --save-dev eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard -npm install --save-dev eslint-plugin-prettier prettier +npm install --save-dev eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node +npm install --save-dev eslint-plugin-prettier eslint-config-prettier prettier-config-standard +npm install --save-dev --save-exact prettier ``` Then install eslint-config-prettier-standard: @@ -30,7 +35,12 @@ npm install --save-dev eslint-config-prettier-standard
Peer Dependencies -**eslint-config-prettier-standard** has three peer dependencies ([**eslint-config-prettier**](https://github.com/prettier/eslint-config-prettier), [**eslint-config-standard**](https://github.com/standard/eslint-config-standard) and [**eslint-plugin-prettier**](https://github.com/prettier/eslint-plugin-prettier)). Each of which have their own peer dependencies. +**eslint-config-prettier-standard** has four peer dependencies: +[**eslint-config-prettier**](https://github.com/prettier/eslint-config-prettier), +[**eslint-config-standard**](https://github.com/standard/eslint-config-standard), +[**eslint-plugin-prettier**](https://github.com/prettier/eslint-plugin-prettier), +and [**prettier-config-standard**](https://github.com/npetruzzelli/prettier-config-standard). +Some of which have their own peer dependencies. | Descendant `peerDependency` | depended upon by | | --------------------------- | ------------------------ | @@ -43,10 +53,13 @@ npm install --save-dev eslint-config-prettier-standard
-## Setup +## Usage -Once you've finished installation, add eslint-config-prettier-standard to the "extends" array in your `.eslintrc.*` file. Make sure to put it last, so that it gets the chance to override other configs. +**Basic Use** +Once you've finished installation, add eslint-config-prettier-standard to the +"extends" array in your ESLint configuration. Make sure to put it last, so that +it gets the chance to override other configs that could conflict with Prettier. ```json { @@ -56,42 +69,184 @@ Once you've finished installation, add eslint-config-prettier-standard to the "e } ``` -If you are making a custom configuration that absolutely must extend a different configuration between Standard and Prettier, you can extend the base configuration instead. +
+Advanced Use + +### Extending The Base Configuration. + +If you are making a custom configuration that absolutely must extend a different +configuration between Standard and Prettier, you can extend the base +configuration instead. ```json { "extends": [ - "prettier-standard/lib/base", + "prettier-standard/eslint-file-base", "foo", "bar", - "prettier", - "prettier/standard" + "prettier-standard/end" ] } ``` -## Extending Prettier +_`prettier-standard/eslint-file-base` is available for those configuring +Prettier through its own configuration files. See "Partial Configurations" for +possible options._ -Prettier is a single rule, so the entire configuration object gets overridden when you extend `prettier/prettier`. See [**eslint-plugin-prettier**](https://github.com/prettier/eslint-plugin-prettier) to see a complete list of options available to you. Any options you don't provide will fallback to the plugin's defaults for that option. +### Other Prettier Configurations -You will have to redefine all Prettier options if you want to change any part of Prettier until if/when the plugin supports individual rules. +**eslint-config-prettier** comes with a number of additional configurations. To +use them, extend them after "prettier-standard". -
-Hypothetical Example - -If the plugin were to support multiple rules in the future, they might look like this: -- `prettier/bracketSpacing` -- `prettier/jsxBracketSameLine` -- `prettier/printWidth` -- `prettier/semi` -- `prettier/singleQuote` -- `prettier/tabWidth` -- `prettier/trailingComma` -- `prettier/useTabs` +```json +{ + "extends": [ + "prettier-standard", + "prettier/flowtype", + "prettier/react" + ] +} +``` +_These configurations disable rules provided by their respective plugins that +could conflict with Prettier. Configurations like this that are provided by +other modules should be placed after "prettier-standard" for consistent and +expect behavior._
+## Available Configurations + +There are two ways to use this configuration. Each option describes how or where +Prettier will be configured. + + +### `eslint-file` + +**`prettier-standard/eslint-file`** is the default configuration, and it can be +referenced with just **`prettier-standard`**. It is effectively the same +configuration used by this configuration prior to version 3. + +It combines the `prettier-standard/eslint-file-base` and `prettier-standard/end` +partial configurations to create a complete configuration. + +```diff + Prettier's configuration will be included in the ESLint configuration. ++ You don't need to worry about a seperate file or property for configuring Prettier +- Extending Prettier options is a little more complex. +- Prettier used for other file types (such as stylesheets or HTML) will need to be configured seperately. +``` + +```jsonc +{ + "extends": [ + "prettier-standard" + + // EFFECTIVELY THE SAME AS: + // "prettier-standard/eslint-file" + ] +} +``` + + +### `prettier-file` + +**`prettier-standard/prettier-file`** combines the +`prettier-standard/prettier-file-base` and `prettier-standard/end` partial +configurations to create a complete configuration. + +```diff + Prettier is expected to be configured in its own file ++ Extending Prettier options is more simple. ++ Keeps multiple Prettier workflows consistent by configuring it in one location. +- One additional file to setup +``` + +- See Prettier's documentation on the + [Configuration File](https://prettier.io/docs/en/configuration.html) to + learn more. +- We expose a reference to the Prettier configuration for ease of + modification. See "partial configurations" for more information. + + +```jsonc +// .eslintrc.json +{ + "extends": [ + "prettier-standard/prettier-file" + ] +} +``` + +```jsonc +// .prettierrc.json +"prettier-config-standard" +``` + +### Why Configure Prettier In A Seperate File? + +- To make tooling in build systems and IDEs more consistent and to make + Prettier options easier to extend. +- Prettier is used for more than just JavaScript. Configuring it once in a + standard location and letting the tools find it makes maintainence easier + and reduces confusion. It doesn't make sense to maintain a configuration for + ESLint, then again for Stylelint, and again for whatever other language you + may be using Prettier with. + + +## Partial Configurations + +These are provided as a convenience to aid with extending configurations. + +- **eslint-config-prettier-standard/prettierrc**: The Prettier configuration + as an object. Since this won't be used in the context of ESLint's "extends", + the complete module name must be used. This partial configuration is + provided for anyone who absolutely must be certain that they are using the + same version of the Prettier config that this ESLint config can resolve and + consume. + + _In most cases, importing `prettier-config-standard` directly is recommended._ +- **prettier-standard/base**: Extends the JavaScript Standard Style shareable + config and includes the Prettier plugin. +- **prettier-standard/end**: This kicks of the last of the shareable configs + you should be using. Disables conflicting ESLint rules (Including those from + the JavaScript Standard Style plugin) by extending the Prettier shareable + configs. +- **prettier-standard/eslint-file-base**: Extends `prettier-standard/base`. + Sets the `prettier/prettier` ESLint rule to "error", reads + `prettier-standard/prettierrc`, and passes it as the configuration for the + `prettier/prettier` ESLint rule. +- **prettier-standard/prettier-file-base**: Extends `prettier-standard/base`. + Sets the `prettier/prettier` rule to "error". + + +## Extending The Configuration + +Extending ESLint rules works normally, but extending Prettier can range from +simple to complex, depending on how many shareable Prettier configurations you +are working with and what you are trying to accomplish. + +All Prettier options count as a single ESLint `prettier/prettier` rule +configuration, so they can not be individually extended. + +All of your shareable Prettier configurations need to be imported, extended in +the proper order, modified as you desire, and then you export the combined +configuration. + +The following references may be helpful: + +- [Extending Shared Configurations](https://github.com/npetruzzelli/prettier-config-standard#extending-shared-configurations) + from **prettier-config-standard** +- [Sharing configurations](https://prettier.io/docs/en/configuration.html#sharing-configurations) + from Prettier's documentation on the "Configuration File". + + +## Deprecated + +Use of resources in the `lib` directory is deprecated. These resources will be +deleted in a future major release. + + ## "BSD-3-Clause" License - [LICENSE](LICENSE) diff --git a/base.js b/base.js new file mode 100644 index 0000000..9bdc6e1 --- /dev/null +++ b/base.js @@ -0,0 +1,4 @@ +module.exports = { + plugins: ['prettier'], + extends: ['standard'] +} diff --git a/end.js b/end.js new file mode 100644 index 0000000..0d233a7 --- /dev/null +++ b/end.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['prettier', 'prettier/standard'] +} diff --git a/eslint-file-base.js b/eslint-file-base.js new file mode 100644 index 0000000..b06fffc --- /dev/null +++ b/eslint-file-base.js @@ -0,0 +1,8 @@ +const prettierConfig = require('./prettierrc.js') + +module.exports = { + extends: ['./base.js'], + rules: { + 'prettier/prettier': ['error', prettierConfig] + } +} diff --git a/eslint-file.js b/eslint-file.js new file mode 100644 index 0000000..a22a12d --- /dev/null +++ b/eslint-file.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./eslint-file-base.js', './end.js'] +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..289ee06 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('./eslint-file') diff --git a/lib/base.js b/lib/base.js index 9645b0a..c9615f3 100644 --- a/lib/base.js +++ b/lib/base.js @@ -1,24 +1,7 @@ -module.exports = { - plugins: ["prettier"], - extends: ["standard"], - rules: { - "prettier/prettier": [ - "error", - { - bracketSpacing: true, - jsxBracketSameLine: true, - printWidth: 80, - semi: false, +// Legacy "base" configuration +const baseConfig = require('../base.js') +const prettierConfig = require('../prettierrc.js') - /* `singleQuote: true` - * IN PRETTIER IS SIMILAR TO THE ESLINT RULE: - * `quotes: [error, single, { avoidEscape: true }],` - */ - singleQuote: true, - tabWidth: 2, - trailingComma: "none", - useTabs: false - } - ] - } -} +module.exports = Object.assign({}, baseConfig, { + rules: { 'prettier/prettier': ['error', prettierConfig] } +}) diff --git a/lib/prettier-standard.js b/lib/prettier-standard.js index ca503c9..167cc01 100644 --- a/lib/prettier-standard.js +++ b/lib/prettier-standard.js @@ -1,3 +1,7 @@ +const endConfig = require('../end') +const extendsConfig = ['./base.js'].concat(endConfig.extends) + +// Legacy Configuration module.exports = { - extends: ["./base.js", "prettier", "prettier/standard"] + extends: extendsConfig } diff --git a/package.json b/package.json index 1ab51a1..2997c58 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "eslint-config-prettier-standard", - "version": "2.0.0", + "version": "3.0.0", "description": "An ESLint shareable config for projects using 'Prettier' and 'JavaScript Standard Style' as ESLint rules.", - "main": "lib/prettier-standard.js", + "main": "index.js", "repository": { "type": "git", "url": "git@github.com:npetruzzelli/eslint-config-prettier-standard.git" @@ -10,32 +10,36 @@ "keywords": [ "eslint", "eslintconfig", + "eslint-config", "eslintplugin", "eslint-plugin", "JavaScript Standard Style", "jsstandard", "lint", "prettier", + "prettierconfig", + "prettier-config", "standard", "standard style" ], "author": "Nick Petruzzelli ", "license": "BSD-3-Clause", "peerDependencies": { - "eslint-config-prettier": "^2.9.0", - "eslint-config-standard": "^11.0.0", - "eslint-plugin-prettier": "^2.6.0" + "eslint-config-prettier": ">=5.0.0", + "eslint-config-standard": ">=12.0.0", + "eslint-plugin-prettier": ">=3.1.0", + "prettier-config-standard": ">=1.0.0" }, "devDependencies": { - "eslint": "^4.19.1", - "eslint-config-prettier": "^2.9.0", - "eslint-config-standard": "^11.0.0", - "eslint-plugin-import": "^2.11.0", - "eslint-plugin-node": "^6.0.1", - "eslint-plugin-prettier": "^2.6.0", - "eslint-plugin-promise": "^3.7.0", - "eslint-plugin-standard": "^3.0.1", - "lodash.merge": "^4.6.0", - "prettier": "^1.12.1" + "eslint": "^5.16.0", + "eslint-config-prettier": "^5.0.0", + "eslint-config-standard": "^12.0.0", + "eslint-plugin-import": "^2.17.3", + "eslint-plugin-node": "^9.1.0", + "eslint-plugin-prettier": "^3.1.0", + "eslint-plugin-promise": "^4.1.1", + "eslint-plugin-standard": "^4.0.0", + "prettier": "1.18.2", + "prettier-config-standard": "^1.0.1" } } diff --git a/prettier-file-base.js b/prettier-file-base.js new file mode 100644 index 0000000..33c92cc --- /dev/null +++ b/prettier-file-base.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ['./base.js'], + rules: { + 'prettier/prettier': 'error' + } +} diff --git a/prettier-file.js b/prettier-file.js new file mode 100644 index 0000000..95fdcff --- /dev/null +++ b/prettier-file.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./prettier-file-base.js', './end.js'] +} diff --git a/prettierrc.js b/prettierrc.js new file mode 100644 index 0000000..631578b --- /dev/null +++ b/prettierrc.js @@ -0,0 +1 @@ +module.exports = require('prettier-config-standard')