Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Add a prettier config (#46)
Browse files Browse the repository at this point in the history
* Setup prettier config

* eslint --fix with eslint-plugin-prettier on this breaks

* Disable prettier on test source

* Run eslint --fix with prettier config

* Remove format script"

* Rename script to prettier-check

* Remove uncessary rules

* Add a small note about prettier

* Context for disabling

* PR fixes

* Run prettier against /tests

* Point prettier-check to correct config

* v17.2.0-alpha.1

* Add prettier as optional dep

* Reformat after rebase

* Fix lint error

* Change version back to master version
  • Loading branch information
ismail-syed authored Oct 25, 2017
1 parent 1790119 commit 45504b6
Show file tree
Hide file tree
Showing 42 changed files with 1,353 additions and 905 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ This plugin also provides the following tool-specific configurations, which can
- [ava](lib/config/ava.js): Use this for projects that use the [AVA test runner](https://github.com/sindresorhus/ava).
- [flow](lib/config/flow.js): Use this for projects that use [flow](http://flowtype.org) for type checking.
- [jquery](lib/config/jquery.js): Use this for projects that use [jQuery](http://jquery.com).
- [prettier](lib/config/prettier.js): Use [prettier](https://github.com/prettier/prettier) for consistent formatting. Extending this Shopify's prettier config will [override](https://github.com/prettier/eslint-config-prettier/blob/master/index.js) the default Shopify eslint rules in favor of prettier formatting.

### node

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
lodash: require('./lib/config/lodash'),
mocha: require('./lib/config/mocha'),
node: require('./lib/config/node'),
prettier: require('./lib/config/prettier'),
react: require('./lib/config/react'),
},
};
4 changes: 3 additions & 1 deletion lib/config/all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
parser: 'babel-eslint',
Expand Down Expand Up @@ -28,6 +28,7 @@ module.exports = {
'jsx-a11y',
'lodash',
'node',
'prettier',
'promise',
'react',
'shopify',
Expand All @@ -52,6 +53,7 @@ module.exports = {
require('./rules/jsx-a11y'),
require('./rules/lodash'),
require('./rules/node'),
require('./rules/prettier'),
require('./rules/promise'),
require('./rules/react'),
require('./rules/shopify'),
Expand Down
4 changes: 1 addition & 3 deletions lib/config/ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ module.exports = {
sourceType: 'module',
},

plugins: [
'ava',
],
plugins: ['ava'],

rules: require('./rules/ava'),
};
6 changes: 2 additions & 4 deletions lib/config/core.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
plugins: [
'shopify',
],
plugins: ['shopify'],

parserOptions: {
ecmaFeatures: {
Expand Down
14 changes: 3 additions & 11 deletions lib/config/esnext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
extends: 'plugin:shopify/core',
Expand All @@ -16,18 +16,10 @@ module.exports = {
},
},

plugins: [
'babel',
'promise',
'sort-class-members',
'import',
],
plugins: ['babel', 'promise', 'sort-class-members', 'import'],

settings: {
'import/ignore': [
'node_modules',
'\\.s?css',
],
'import/ignore': ['node_modules', '\\.s?css'],
},

rules: merge(
Expand Down
11 changes: 3 additions & 8 deletions lib/config/flow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
parser: 'babel-eslint',
Expand All @@ -12,12 +12,7 @@ module.exports = {
sourceType: 'module',
},

plugins: [
'flowtype',
'shopify',
],
plugins: ['flowtype', 'shopify'],

rules: merge(
require('./rules/flowtype')
),
rules: merge(require('./rules/flowtype')),
};
4 changes: 1 addition & 3 deletions lib/config/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module.exports = {
jquery: true,
},

plugins: [
'shopify',
],
plugins: ['shopify'],

rules: {
'shopify/jquery-dollar-sign-reference': 'error',
Expand Down
4 changes: 1 addition & 3 deletions lib/config/lodash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {
plugins: [
'lodash',
],
plugins: ['lodash'],

rules: require('./rules/lodash'),
};
26 changes: 9 additions & 17 deletions lib/config/mocha.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
env: {
mocha: true,
},

plugins: [
'mocha',
'chai-expect',
'shopify',
],
plugins: ['mocha', 'chai-expect', 'shopify'],

rules: merge(
require('./rules/mocha'),
require('./rules/chai-expect'),
{
'shopify/sinon-prefer-meaningful-assertions': 'error',
// Chai expect syntax produces unused expression warnings
'no-unused-expressions': 'off',
// Chai expect syntax can have long chained calls
'newline-per-chained-call': 'off',
}
),
rules: merge(require('./rules/mocha'), require('./rules/chai-expect'), {
'shopify/sinon-prefer-meaningful-assertions': 'error',
// Chai expect syntax produces unused expression warnings
'no-unused-expressions': 'off',
// Chai expect syntax can have long chained calls
'newline-per-chained-call': 'off',
}),
};
4 changes: 1 addition & 3 deletions lib/config/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module.exports = {
node: true,
},

plugins: [
'node',
],
plugins: ['node'],

rules: require('./rules/node'),
};
20 changes: 20 additions & 0 deletions lib/config/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
extends: ['plugin:shopify/esnext', 'prettier'],

plugins: ['prettier'],

rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: false,
},
],

// rules to disable to prefer prettier
'shopify/binary-assignment-parens': 'off',
},
};
24 changes: 10 additions & 14 deletions lib/config/react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var merge = require('merge');
const merge = require('merge');

module.exports = {
extends: 'plugin:shopify/esnext',
Expand All @@ -17,17 +17,13 @@ module.exports = {
ReactClass: true,
},

plugins: [
'react',
'jsx-a11y',
],
plugins: ['react', 'jsx-a11y'],

rules: merge(
require('./rules/react'),
require('./rules/jsx-a11y'),
{
// Not using `this` is fine in some lifecycle hooks
'class-methods-use-this': ['error', {
rules: merge(require('./rules/react'), require('./rules/jsx-a11y'), {
// Not using `this` is fine in some lifecycle hooks
'class-methods-use-this': [
'error',
{
exceptMethods: [
'render',
'getChildContext',
Expand All @@ -39,7 +35,7 @@ module.exports = {
'componentDidUpdate',
'componentWillUnmount',
],
}],
}
),
},
],
}),
};
10 changes: 5 additions & 5 deletions lib/config/rules/best-practices.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ module.exports = {
// Enforce that class methods utilize this
'class-methods-use-this': 'error',
// Specify the maximum cyclomatic complexity allowed in a program
'complexity': 'off',
complexity: 'off',
// Require return statements to either always or never specify values
'consistent-return': 'error',
// Specify curly brace conventions for all control statements
'curly': ['error', 'all'],
curly: ['error', 'all'],
// Require default case in switch statements
'default-case': 'off',
// Encourages use of dot notation whenever possible
'dot-notation': ['error', {allowKeywords: true}],
// Enforces consistent newlines before or after dots
'dot-location': ['error', 'property'],
// Require the use of === and !==
'eqeqeq': ['error', 'allow-null'],
eqeqeq: ['error', 'allow-null'],
// Make sure for-in loops have an if statement
'guard-for-in': 'error',
// Disallow the use of alert, confirm, and prompt
Expand Down Expand Up @@ -135,13 +135,13 @@ module.exports = {
// Require using Error objects as Promise rejection reasons
'prefer-promise-reject-errors': ['error', {allowEmptyReject: true}],
// Require use of the second argument for parseInt()
'radix': 'error',
radix: 'error',
// Disallow async functions which have no await expression
'require-await': 'error',
// Requires to declare all vars on top of their containing scope
'vars-on-top': 'off',
// Require immediate function invocation to be wrapped in parentheses
'wrap-iife': ['error', 'inside'],
// Require or disallow Yoda conditions
'yoda': ['error', 'never'],
yoda: ['error', 'never'],
};
13 changes: 8 additions & 5 deletions lib/config/rules/flowtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ module.exports = {
// Disallows Flow type imports, aliases, and annotations in files missing a valid Flow file declaration (or a @noflow annotation).
'flowtype/no-types-missing-file-annotation': 'error',
// Warns against weak type annotations any, Object and Function.
'flowtype/no-weak-types': ['error', {
any: false,
Object: false,
Function: true,
}],
'flowtype/no-weak-types': [
'error',
{
any: false,
Object: false,
Function: true,
},
],
// Enforces consistent separators between properties in Flow object types.
'flowtype/object-type-delimiter': ['error', 'comma'],
// Requires that all function parameters have type annotations.
Expand Down
12 changes: 6 additions & 6 deletions lib/config/rules/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ module.exports = {
// Ensure consistent use of file extension within the import path
'import/extensions': ['error', {js: 'never', json: 'always'}],
// Enforce a convention in module import order
'import/order': ['error', {
groups: [
['builtin', 'external'],
['internal', 'parent', 'sibling'],
],
}],
'import/order': [
'error',
{
groups: [['builtin', 'external'], ['internal', 'parent', 'sibling']],
},
],
// Enforce a newline after import statements
'import/newline-after-import': 'error',
// Prefer a default export if module exports a single name
Expand Down
1 change: 0 additions & 1 deletion lib/config/rules/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
// Avoid creating new promises outside of utility libs (use pify instead)
'promise/avoid-new': 'off',


// Async/Await Rules

// Prefer await to then() for reading Promise values
Expand Down
Loading

0 comments on commit 45504b6

Please sign in to comment.