Skip to content

Commit

Permalink
Add eslint config (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Walbø Johnsgård committed Jun 24, 2020
1 parent 531b367 commit 608d684
Show file tree
Hide file tree
Showing 23 changed files with 2,030 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/composer.lock
node_modules
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "dekodeinteraktiv/coding-standards",
"description": "Dekode Coding Standards",
"type": "phpcodesniffer-standard",
"require": {
"wp-coding-standards/wpcs": "^2.3",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2",
"automattic/phpcs-neutron-standard": "^1.6"
},
"license": "MIT"
"name": "dekodeinteraktiv/coding-standards",
"description": "Dekode Coding Standards",
"type": "phpcodesniffer-standard",
"require": {
"wp-coding-standards/wpcs": "^2.3",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2",
"automattic/phpcs-neutron-standard": "^1.6"
},
"license": "MIT",
"archive": {
"exclude": [ "/packages" ]
}
}
3 changes: 3 additions & 0 deletions packages/eslint-plugin/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./lib/configs/base.js"
}
1 change: 1 addition & 0 deletions packages/eslint-plugin/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.eslintrc
1 change: 1 addition & 0 deletions packages/eslint-plugin/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
Empty file.
21 changes: 21 additions & 0 deletions packages/eslint-plugin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Dekode Interaktiv AS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @dekode/eslint-plugin
Dekodes's ESLint plugin, following our styleguide.

## Installation
You'll first need to install [ESLint](http://eslint.org):

```
$ npm i eslint --save-dev
```

Next, install [`@dekode/eslint-plugin`](https://github.com/DekodeInteraktiv/coding-standards/tree/master/packages/eslint-plugin):

```
$ npm install @dekode/eslint-plugin --save-dev
```

## Usage
This plugin exports a [`base` config](index.js) that enforces best practices.

Create your own `.eslintrc.js` configuration file:

```js
{
"extends": "plugin:@dekode/base",
"plugins": [
"@dekode"
]
}
```

Or see the [ESLint docs](http://eslint.org/docs/user-guide/configuring.html#configuration-file-formats) for more information about configuration file formats.

You can also stack any of the extra shared configs on top of the "base" config by extending an array of linting configs. For example, this package provides a React linting config, which can be added to the base config with the following configuration file:

```js
{
"extends": [
"plugin:@dekode/base",
"plugin:@dekode/react"
]
}
```

## Available rulesets
The following rulesets are available:

* **base**: Enforces best practices and possible errors
* **react**: Enforces best React.js practices
6 changes: 6 additions & 0 deletions packages/eslint-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
configs: {
base: require( './lib/configs/base' ),
react: require( './lib/configs/react' ),
},
};
23 changes: 23 additions & 0 deletions packages/eslint-plugin/lib/configs/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* External dependencies
*/
const merge = require( 'merge' );

module.exports = {
plugins: [
'import',
'jsx-a11y',
'react',
],
rules: merge(
require( './rules/best-practices' ),
require( './rules/esnext' ),
require( './rules/import' ),
require( './rules/jsx-a11y' ),
require( './rules/possible-errors' ),
require( './rules/react' ),
require( './rules/strict' ),
require( './rules/stylistic-issues' ),
require( './rules/variables' ),
),
};
28 changes: 28 additions & 0 deletions packages/eslint-plugin/lib/configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* External dependencies
*/
const merge = require( 'merge' );

module.exports = {
parser: 'babel-eslint',
env: {
browser: true,
es6: true,
jest: true,
node: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [ 'import' ],
rules: merge(
require( './rules/best-practices' ),
require( './rules/esnext' ),
require( './rules/import' ),
require( './rules/possible-errors' ),
require( './rules/strict' ),
require( './rules/stylistic-issues' ),
require( './rules/variables' ),
),
};
27 changes: 27 additions & 0 deletions packages/eslint-plugin/lib/configs/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
const merge = require( 'merge' );

module.exports = {
plugins: [
'jsx-a11y',
'react',
'react-hooks',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
settings: {
react: {
pragma: 'React',
version: '16',
},
},
rules: merge(
require( './rules/jsx-a11y' ),
require( './rules/react' ),
),
};
Loading

0 comments on commit 608d684

Please sign in to comment.