Repository: prettier/prettier-eslint
Pull request #65 (2017-04-13 17:45:17)

feat: upgrade prettier to 1.0.0!
This adds support for the new `semi` and `useTabs` options!


Patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8e91a7f..bfa8552 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -12,7 +12,7 @@ Thanks for being willing to contribute!
 3. `$ npm start validate` to validate you've got it working
 4. Create a branch for your PR
 
-This project uses [`p-s`][p-s] and you can run `npm start` to see what scripts are available.
+This project uses [`nps`][nps] and you can run `npm start` to see what scripts are available.
 
 ## Add yourself as a contributor
 
@@ -20,7 +20,7 @@ This project follows the [all contributors][all-contributors] specification. To
 contributors on the README.md, please use the automated script as part of your PR:
 
 ```console
-npm start addContributor <YOUR_GITHUB_USERNAME>
+npm start contributors.add
 ```
 
 Follow the prompt. If you've already added yourself to the list and are making a new type of contribution, you can run
@@ -64,4 +64,4 @@ Also, please watch the repo and respond to questions/bug reports/feature request
 [convention]: https://github.com/conventional-changelog/conventional-changelog-angular/blob/ed32559941719a130bb0327f886d6a32a8cbc2ba/convention.md
 [all-contributors]: https://github.com/kentcdodds/all-contributors
 [ROADMAP]: ./other/ROADMAP.md
-[p-s]: https://npmjs.com/package/p-s
+[nps]: https://npmjs.com/package/nps
diff --git a/README.md b/README.md
index 586067f..2453541 100644
--- a/README.md
+++ b/README.md
@@ -145,22 +145,24 @@ the inference is done for each option (what rule(s) are referenced, etc.) and
 
 **Defaults** if you have all of the relevant ESLint rules disabled (or have
 ESLint disabled entirely via `/* eslint-disable */` then prettier options will
-fall back to the defaults:
+fall back to the `prettier` defaults:
 
 ```javascript
 {
   printWidth: 80,
   tabWidth: 2,
+  singleQuote: false,
+  trailingComma: 'none',
+  bracketSpacing: true,
+  semi: true,
+  useTabs: false,
+  // prettier-eslint doesn't currently support
+  // inferring these two (Pull Requests welcome):
   parser: 'babylon',
-  singleQuote: true,
-  trailingComma: 'all',
-  bracketSpacing: false,
+  jsxBracketSameLine: false,
 }
 ```
 
-I set these defaults based on my own preferences. If you'd like to see these
-defaults changed, please [make a pull request][pr].
-
 ## Inspiration
 
 - [`prettier`][prettier]
diff --git a/package-scripts.js b/package-scripts.js
index 7c5bcf5..8b1869e 100644
--- a/package-scripts.js
+++ b/package-scripts.js
@@ -1,40 +1,76 @@
-/* eslint max-len:0 */
+const npsUtils = require('nps-utils')
+
+const series = npsUtils.series
+const concurrent = npsUtils.concurrent
+const rimraf = npsUtils.rimraf
+
 module.exports = {
   scripts: {
+    contributors: {
+      add: {
+        description: 'When new people contribute to the project, run this',
+        script: 'all-contributors add',
+      },
+      generate: {
+        description: 'Update the badge and contributors table',
+        script: 'all-contributors generate',
+      },
+    },
     commit: {
       description: 'This uses commitizen to help us generate well formatted commit messages',
       script: 'git-cz',
     },
-    test: {default: `jest --coverage`, watch: 'jest --watch'},
+    test: {
+      default: 'jest --coverage',
+      watch: 'jest --watch',
+    },
     build: {
       description: 'delete the dist directory and run babel to build the files',
-      script: 'rimraf dist && babel --copy-files --out-dir dist --ignore *.test.js,__mocks__ src',
+      script: series(
+        rimraf('dist'),
+        'babel --copy-files --out-dir dist --ignore *.test.js,__mocks__ src'
+      ),
+    },
+    lint: {
+      description: 'lint the entire project',
+      script: 'eslint .',
     },
-    lint: {description: 'lint the entire project', script: 'eslint .'},
     reportCoverage: {
       description: 'Report coverage stats to codecov. This should be run after the `test` script',
       script: 'codecov',
     },
     release: {
       description: 'We automate releases with semantic-release. This should only be run on travis',
-      script: 'semantic-release pre && npm publish && semantic-release post',
+      script: series(
+        'semantic-release pre',
+        'npm publish',
+        'semantic-release post'
+      ),
     },
     validate: {
       description: 'This runs several scripts to make sure things look good before committing or on clean install',
-      script: 'nps format && nps -p lint,build,test',
+      script: concurrent.nps('lint', 'build', 'test'),
     },
     format: {
       description: 'Formats everything with prettier-eslint',
       script: 'prettier-eslint src/*.js src/**/*.js --write',
     },
-    addContributor: {
-      description: 'When new people contribute to the project, run this',
-      script: 'all-contributors add',
-    },
-    generateContributors: {
-      description: 'Update the badge and contributors table',
-      script: 'all-contributors generate',
-    },
   },
-  options: {silent: false},
+  options: {
+    silent: false,
+  },
 }
+
+// this is not transpiled
+/*
+  eslint
+  max-len: 0,
+  comma-dangle: [
+    2,
+    {
+      arrays: 'always-multiline',
+      objects: 'always-multiline',
+      functions: 'never'
+    }
+  ]
+ */
diff --git a/package.json b/package.json
index baa86c6..403d70c 100644
--- a/package.json
+++ b/package.json
@@ -19,36 +19,37 @@
   "dependencies": {
     "common-tags": "^1.4.0",
     "dlv": "^1.1.0",
-    "eslint": "^3.17.0",
+    "eslint": "^3.19.0",
     "indent-string": "^3.1.0",
     "lodash.merge": "^4.6.0",
     "loglevel-colored-level-prefix": "^1.0.0",
-    "prettier": "^0.22.0",
+    "prettier": "^1.0.2",
     "pretty-format": "^19.0.0",
     "require-relative": "^0.8.7"
   },
   "devDependencies": {
-    "all-contributors-cli": "^4.0.0",
-    "babel-cli": "^6.18.0",
-    "babel-jest": "^18.0.0",
+    "all-contributors-cli": "^4.1.0",
+    "babel-cli": "^6.24.1",
+    "babel-jest": "^19.0.0",
     "babel-polyfill": "^6.16.0",
-    "babel-preset-env": "^1.2.1",
-    "babel-preset-stage-2": "^6.18.0",
-    "babel-register": "^6.18.0",
+    "babel-preset-env": "^1.3.3",
+    "babel-preset-stage-2": "^6.24.1",
+    "babel-register": "^6.24.1",
     "chalk": "^1.1.3",
-    "codecov": "^1.0.1",
+    "codecov": "^2.1.0",
     "commitizen": "^2.8.6",
     "cz-conventional-changelog": "^2.0.0",
-    "eslint-config-kentcdodds": "^12.0.0",
-    "husky": "^0.13.1",
+    "eslint-config-kentcdodds": "^12.2.1",
+    "husky": "^0.13.3",
     "jest-cli": "^19.0.1",
+    "nps": "^5.0.5",
+    "nps-utils": "^1.2.0",
     "opt-cli": "^1.5.1",
-    "p-s": "^3.0.3",
-    "prettier-eslint-cli": "^3.0.0",
+    "prettier-eslint-cli": "^3.2.0",
     "rimraf": "^2.5.4",
     "semantic-release": "^6.3.2",
     "strip-indent": "^2.0.0",
-    "validate-commit-msg": "^2.8.2"
+    "validate-commit-msg": "^2.12.1"
   },
   "engines": {
     "node": ">=4.0.0"
diff --git a/src/utils.js b/src/utils.js
index 0298916..e1b1719 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -30,6 +30,14 @@ const OPTION_GETTERS = {
     ruleValue: rules => getRuleValue(rules, 'object-curly-spacing', 'never'),
     ruleValueToPrettierOption: value => getBraketSpacing(value),
   },
+  semi: {
+    ruleValue: rules => getRuleValue(rules, 'semi', 'always'),
+    ruleValueToPrettierOption: value => value === 'always',
+  },
+  useTabs: {
+    ruleValue: rules => getRuleValue(rules, 'indent', 2),
+    ruleValueToPrettierOption: value => value === 'tab',
+  },
 }
 
 /* eslint import/prefer-default-export:0 */
@@ -62,24 +70,23 @@ function getRelevantESLintConfig(eslintConfig) {
   ]
 
   logger.debug('reducing eslint rules down to relevant rules only')
-  const relevantRules = Object.keys(rules).reduce(
-    (rulesAccumulator, ruleName) => {
-      if (rulesThatWillNeverBeFixable.indexOf(ruleName) === -1) {
-        logger.trace(
-          `adding to relevant rules:`,
-          JSON.stringify({[ruleName]: rules[ruleName]}),
-        )
-        rulesAccumulator[ruleName] = rules[ruleName]
-      } else {
-        logger.trace(
-          `omitting from relevant rules:`,
-          JSON.stringify({[ruleName]: rules[ruleName]}),
-        )
-      }
-      return rulesAccumulator
-    },
-    {},
-  )
+  const relevantRules = Object.keys(
+    rules,
+  ).reduce((rulesAccumulator, ruleName) => {
+    if (rulesThatWillNeverBeFixable.indexOf(ruleName) === -1) {
+      logger.trace(
+        `adding to relevant rules:`,
+        JSON.stringify({[ruleName]: rules[ruleName]}),
+      )
+      rulesAccumulator[ruleName] = rules[ruleName]
+    } else {
+      logger.trace(
+        `omitting from relevant rules:`,
+        JSON.stringify({[ruleName]: rules[ruleName]}),
+      )
+    }
+    return rulesAccumulator
+  }, {})
 
   return {
     // defaults
@@ -133,7 +140,7 @@ function configureOptions(prettierOptions, key, options, rules) {
 }
 
 function getTabWidth(value) {
-  // As prettier does not support tabs use prettier default if `value` is `tab`.
+  // if it's set to tabs, then the tabWidth value doesn't matter
   return value === 'tab' ? RULE_DISABLED : value
 }
 


Test patch:
diff --git a/src/index.test.js b/src/index.test.js
index 8822886..c8de21d 100644
--- a/src/index.test.js
+++ b/src/index.test.js
@@ -34,6 +34,12 @@ const tests = [
     output: 'const { foo } = bar',
   },
   {
+    // this one's actually hard to test now. This test doesn't
+    // really do too much. Before, when prettier didn't support
+    // semi, it was easy to tell based on the presence of the
+    // semicolon. Now prettier removes the semicolon so I'm
+    // honestly not sure how to test that prettier fixed
+    // something that eslint fixed
     title: 'with prettierLast: true',
     input: {
       text: defaultInputText(),
@@ -309,7 +315,7 @@ function prettierLastOutput() {
   return `
     function foo() {
       // stuff
-      console.log('Hello world!', and, stuff);
+      console.log('Hello world!', and, stuff)
     }
   `
 }
diff --git a/src/utils.test.js b/src/utils.test.js
index 7ac980e..96d615f 100644
--- a/src/utils.test.js
+++ b/src/utils.test.js
@@ -151,13 +151,23 @@ const getPrettierOptionsFromESLintRulesTests = [
     },
     options: {trailingComma: 'none'},
   },
-  // prettier doesn't allow tabs,
-  // so we'll just go with the default and let eslint fix it
-  {rules: {indent: [2, 'tab']}, options: {}},
   {rules: {'max-len': ['error', {code: 120}]}, options: {printWidth: 120}},
   // If an ESLint rule is disabled fall back to prettier defaults.
   {rules: {'max-len': [0, {code: 120}]}, options: {}},
   {rules: {quotes: ['off', {code: 120}]}, options: {}},
+  {rules: {semi: 'off'}, options: {}},
+  {rules: {semi: ['off', 'never']}, options: {}},
+  {rules: {semi: ['warn', 'always']}, options: {}},
+  {rules: {semi: ['warn', 'always']}, options: {semi: true}},
+  {rules: {semi: ['error', 'never']}, options: {semi: false}},
+  {rules: {semi: [2, 'never']}, options: {semi: false}},
+  {rules: {semi: [2, 'never']}, options: {semi: false}},
+  {rules: {indent: 'off'}, options: {}},
+  {rules: {indent: ['off', 'tab']}, options: {}},
+  {rules: {indent: ['warn', 2]}, options: {useTabs: false, tabWidth: 2}},
+  {rules: {indent: ['warn', 4]}, options: {useTabs: false, tabWidth: 4}},
+  {rules: {indent: ['error', 'tab']}, options: {useTabs: true}},
+  {rules: {indent: [2, 'tab']}, options: {useTabs: true}},
 ]
 
 defaultEslintConfigTests.forEach(({config, defaults, result}, index) => {