Skip to content

Commit

Permalink
Add Prettier (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclindner authored Feb 16, 2019
1 parent c8a090d commit f86854b
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 116 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Removed

## [6.0.0] - 2019-02-16
### Added
* Prettier support via `eslint-plugin-prettier`. Three options have been configured. `endOfLine` is set to `lf`. `printWidth` is set to `124`. `singleQuote` is set to `true`.

### Changed
* Deferred rules covered by `eslint-config-prettier` to Prettier.

## [5.2.0] - 2019-01-27
### Changed
* Updated [max-params](https://eslint.org/docs/rules/max-params) rule to allow 6 params.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ First thing first, let's make sure you have the necessary pre-requisites.
### Command

```bash
npm install eslint-config-tc eslint eslint-plugin-import --save-dev
npm install eslint-config-tc eslint eslint-plugin-import eslint-plugin-prettier prettier --save-dev
```

> eslint, eslint-plugin-import, eslint-plugin-prettier, and prettier are peer dependencies and must be installed.
## Usage

Add the following to your `.eslintrc.json` file:
Expand Down
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
/* eslint id-length: 'off', array-bracket-newline: 'off', array-element-newline: 'off' */

const bestPractices = require.resolve('./rules/best-practices');
const errors = require.resolve('./rules/errors');
const es6 = require.resolve('./rules/es6');
const node = require.resolve('./rules/node');
const style = require.resolve('./rules/style');
const variables = require.resolve('./rules/variables');
const prettier = require.resolve('./rules/prettier');

module.exports = {
'extends': [
extends: [
'eslint-config-airbnb-base',
'eslint-config-prettier',
bestPractices,
errors,
es6,
node,
style,
variables
variables,
prettier
],
'parserOptions': {
plugins: ['prettier'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
'env': {
env: {
node: true
},
'rules': {
rules: {
strict: 'error'
},
'overrides': [
overrides: [
{
files: [
'**/*.spec.js',
'**/*.test.js',
'**/tests-*.js'
],
files: ['**/*.spec.js', '**/*.test.js', '**/tests-*.js'],
env: {
jest: true,
mocha: true
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-tc",
"version": "5.2.0",
"version": "6.0.0",
"description": "ESLint shareable config for JavaScript projects",
"keywords": [
"eslintconfig",
Expand All @@ -26,25 +26,28 @@
"eslint": "eslint . --format=node_modules/eslint-formatter-pretty",
"lint": "npm run npmpackagejsonlint && npm run eslint",
"npmpackagejsonlint": "npmPkgJsonLint .",
"test": "mocha"
"test": "jest"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.12.1",
"eslint": "^5.14.0",
"eslint-formatter-pretty": "^2.1.1",
"eslint-plugin-import": "^2.15.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-prettier": "^3.0.1",
"is-plain-obj": "^1.1.0",
"mocha": "^5.2.0",
"jest": "^24.1.0",
"npm-package-json-lint": "^3.4.1",
"npm-package-json-lint-config-tc": "^2.1.0",
"temp-write": "^3.4.0"
"prettier": "^1.16.4"
},
"dependencies": {
"eslint-config-airbnb-base": "^13.1.0"
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.0.0"
},
"peerDependencies": {
"eslint": "^5.12.1",
"eslint-plugin-import": "^2.15.0"
"eslint-plugin-import": ">= 2",
"eslint-plugin-prettier": ">= 3",
"prettier": ">= 1"
},
"engines": {
"node": ">=6.0.0",
Expand Down
5 changes: 2 additions & 3 deletions rules/best-practices.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module.exports = {
rules: {
'accessor-pairs': 'error',
'class-methods-use-this': 'error',
'complexity': 'error',
'curly': 'error',
complexity: 'error',
'default-case': 'error',
'eqeqeq': 'error',
eqeqeq: 'error',
'no-div-regex': 'error',
'no-empty-function': 'error',
'no-eq-null': 'error',
Expand Down
9 changes: 0 additions & 9 deletions rules/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
module.exports = {
rules: {
'no-constant-condition': 'error',
'no-extra-parens': ['error', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,

// delegate to eslint-plugin-react
ignoreJSX: 'all',
enforceForArrowConditionals: false
}],
'no-prototype-builtins': 'off',
'require-atomic-updates': 'error',
'valid-jsdoc': 'error'
Expand Down
3 changes: 0 additions & 3 deletions rules/es6.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
rules: {
'array-bracket-newline': ['error', 'consistent'],
'array-element-newline': ['error', 'consistent'],
'arrow-parens': ['error', 'always'],
'max-classes-per-file': 'error',
'no-duplicate-imports': 'error',
'no-useless-rename': 'error',
Expand Down
13 changes: 13 additions & 0 deletions rules/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
rules: {
'prettier/prettier': [
'error',
{
bracketSpacing: false,
endOfLine: 'lf',
printWidth: 124,
singleQuote: true
}
]
}
};
62 changes: 18 additions & 44 deletions rules/style.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
module.exports = {
rules: {
'block-spacing': 'off',
'brace-style': 'error',
'camelcase': 'error',
'comma-dangle': ['error', 'never'],
camelcase: 'error',
'func-names': 'off',
'func-style': ['error', 'expression'],
'function-paren-newline': ['error', 'never'],
'id-length': ['error', {
min: 1,
max: 25
}],
'keyword-spacing': 'error',
'id-length': [
'error',
{
min: 1,
max: 25
}
],
'line-comment-position': ['error', {position: 'above'}],
'lines-around-comment': ['error', {
allowArrayStart: false,
allowArrayEnd: false,
allowBlockStart: true,
allowBlockEnd: false,
allowObjectStart: false,
allowObjectEnd: false,
afterBlockComment: false,
afterLineComment: false,
beforeBlockComment: true,
beforeLineComment: true
}],
'max-depth': ['error', 4],
'max-len': 'off',
'max-lines-per-function': 'error',
'max-nested-callbacks': ['error', 4],
'max-params': ['error', 6],
Expand All @@ -36,12 +21,6 @@ module.exports = {
'no-inline-comments': 'error',
'no-negated-condition': 'error',
'no-underscore-dangle': 'off',
'object-curly-newline': ['error', {
ObjectExpression: {consistent: true},
ObjectPattern: 'never'
}],
'object-curly-spacing': ['error', 'never'],
'padded-blocks': ['error', {classes: 'always'}],
'padding-line-between-statements': [
'error',
{blankLine: 'always', prev: '*', next: 'return'},
Expand All @@ -61,22 +40,17 @@ module.exports = {
{blankLine: 'any', prev: 'cjs-import', next: '*'},
{blankLine: 'any', prev: 'cjs-import', next: 'cjs-import'}
],
'quote-props': ['error', 'consistent-as-needed', {keywords: true}],
'require-jsdoc': ['error', {
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: false
'require-jsdoc': [
'error',
{
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: false
}
}
}],
'semi-spacing': ['error', {
before: false,
after: false
}],
],
'sort-vars': 'error',
'space-before-function-paren': ['error', 'never'],
'spaced-comment': ['error', 'always'],
'switch-colon-spacing': 'error',
'wrap-regex': 'error'
'spaced-comment': ['error', 'always']
}
};
11 changes: 0 additions & 11 deletions test/helper/testHelper.js

This file was deleted.

48 changes: 25 additions & 23 deletions test/tests.test.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
const chai = require('chai');
const eslint = require('eslint');
const isPlainObj = require('is-plain-obj');
const eslintConfig = require('../index.js');
const lint = require('./helper/testHelper.js');

const should = chai.should();

describe('eslint config tests', () => {
context('eslint object', () => {
it('should be an object', () => {
isPlainObj(eslintConfig).should.be.true;
describe('eslint object', () => {
test('should be an object', () => {
expect(isPlainObj(eslintConfig)).toBeTruthy();
});
});

context('parserOptions', () => {
it('should be an object', () => {
isPlainObj(eslintConfig.parserOptions).should.be.true;
describe('parserOptions', () => {
test('should be an object', () => {
expect(isPlainObj(eslintConfig.parserOptions)).toBeTruthy();
});
});

context('env', () => {
it('should be an array', () => {
isPlainObj(eslintConfig.env).should.be.true;
describe('env', () => {
test('should be an array', () => {
expect(isPlainObj(eslintConfig.env)).toBeTruthy();
});
});

context('rules', () => {
it('should be an object', () => {
isPlainObj(eslintConfig.rules).should.be.true;
describe('rules', () => {
test('should be an object', () => {
expect(isPlainObj(eslintConfig.rules)).toBeTruthy();
});
});

context('run eslint and make sure it runs', () => {
it('eslint should run without failing', () => {
describe('run eslint and make sure it runs', () => {
test('eslint should run without failing', () => {
const code = 'console.log("doh, I used the wrong quotes");\n';
const expectedErrorLineNum = 1;
const expectedErrorColumnNum = 1;
const errors = lint(code, eslintConfig);
const linter = new eslint.CLIEngine({
useEslintrc: false,
baseConfig: eslintConfig
});

const errors = linter.executeOnText(code).results[0].messages;
const error = errors[0];

error.ruleId.should.equal('no-console');
error.line.should.equal(expectedErrorLineNum);
error.column.should.equal(expectedErrorColumnNum);
error.message.should.equal('Unexpected console statement.');
expect(error.ruleId).toStrictEqual('no-console');
expect(error.line).toStrictEqual(expectedErrorLineNum);
expect(error.column).toStrictEqual(expectedErrorColumnNum);
expect(error.message).toStrictEqual('Unexpected console statement.');
});
});
});

0 comments on commit f86854b

Please sign in to comment.