Skip to content

Commit

Permalink
Refonte majeure de eslint-config-udes (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrancourt authored Feb 14, 2018
1 parent 969f569 commit bf56d5f
Show file tree
Hide file tree
Showing 13 changed files with 1,004 additions and 458 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.php]
indent_size = 4
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
module.exports = {
// Extends the UdeS ESLint config
extends: [
'./index.js',
],
}

// Defines global variables that are predefined
env: {
// Node.js global variables and Node.js scoping
node: true,
},

// Limit ESLint to a specific project
root: true,
};
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Université de Sherbrooke
Copyright (c) 2017-2018 Université de Sherbrooke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,66 @@
# eslint-config-udes

[![Greenkeeper badge](https://badges.greenkeeper.io/UdeS-STI/eslint-config-udes.svg)](https://greenkeeper.io/)
[![CircleCI](https://circleci.com/gh/UdeS-STI/eslint-config-udes.svg?style=svg)](https://circleci.com/gh/UdeS-STI/eslint-config-udes)
[![Greenkeeper badge](https://badges.greenkeeper.io/UdeS-STI/eslint-config-udes.svg)](https://greenkeeper.io/)
[![npm](https://img.shields.io/npm/v/eslint-config-udes.svg?style=flat-square)](https://www.npmjs.com/package/eslint-config-udes)

ESLint shareable config for the UdeS JavaScript style guide
ESLint shareable config for the UdeS JavaScript style guide.

## Installation
```bash
$ npm i -D eslint-config-udes
$ npm install eslint-config-udes --save-dev
```

## Usage
- Add the extends attribute to your `.eslintrc.js`
- Add the extends attribute to your `.eslintrc.js`:

```javacript
module.exports = {
// Extends the UdeS ESLint config
extends: 'eslint-config-udes',
// Limit ESLint to a specific project
root: true
root: true,
}
```
- Add the wanted scripts to your `package.json`

- If you use one of the supported language/framework, you should use the corresponding extends:
```
// Extends the UdeS ESLint config for Polymer 2 application
extends: 'eslint-config-udes/polymer-2-application',
// Extends the UdeS ESLint config for Polymer 2 element
extends: 'eslint-config-udes/polymer-2-element',
// Extends the UdeS ESLint config for Node.js 8 application
extends: 'eslint-config-udes/node-8',
// Extends the UdeS ESLint config for React application and element
extends: 'eslint-config-udes/react',
```

- Add the wanted scripts to your `package.json`:

```json
{
"scripts": {
"format": "npm run format:js && npm run format:json",
"format:js": "eslint . --ext js,html --ignore-path .gitignore --fix",
"format:json": "eslint . --ext .json --ignore-path .gitignore --fix",
"lint": "npm run lint:js && npm run lint:json && npm run lint:polymer",
"lint:js": "eslint . --ext js,html --ignore-path .gitignore",
"lint:json": "eslint . --ext .json --ignore-path .gitignore",
"lint:polymer": "polymer lint"
},
"pre-commit": [
"lint"
]
"format": "npm-run-all format:*",
"format:js": "eslint . --ext js --fix",
"format:json": "eslint . --ext json --fix",
"format:markdown": "eslint . --ext md --fix",
"lint": "npm-run-all lint:*",
"lint:js": "eslint . --ext js",
"lint:json": "eslint . --ext json",
"lint:markdown": "eslint . --ext md"
}
}
```

- If you use the `npm-run-all` module, don't forget to add it to your devDependencies:
```bash
npm install npm-run-all --save-dev
```

## License
The [MIT License][1] (MIT)

Expand Down
109 changes: 51 additions & 58 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,87 @@
module.exports = {
// Extends the JavaScript Standard Style
extends: ['eslint-config-standard'],
extends: [
'eslint:recommended',
'google',
],

// Supported JavaScript language options
parserOptions: {
// Enables ES6/ES2015 syntax
ecmaVersion: 6,
},

// Defines global variables that are predefined
env: {
// Browser global variables
browser: true,

// Enable ES6 features (automatically sets the ecmaVersion parser option to 6)
es6: true,

// Node.js global variables and Node.js scoping
node: true,
},

// Use of third-party plugins
plugins: [
// Allows linting and fixing inline scripts contained in HTML files
'eslint-plugin-html',

// Lint JSON files
'eslint-plugin-json',

// Lint markdown files
'eslint-plugin-markdown',
],

// Custom rules
rules: {
// Enforces parentheses around arrow function parameters regardless of arity
'arrow-parens': [
'error', 'as-needed', {
// Require parens if the function body is in an instructions block
requireForBlockBody: true,
}],

// Requires trailing commas when the last element or property is in a different line than the closing ] or }
'comma-dangle': ['error', {
'arrays': 'always-multiline', // let [a,] = [1,]
'exports': 'always-multiline', // export {a,}
'comma-dangle': [
'error', {
'arrays': 'always-multiline', // let [a,] = [1,]
'exports': 'always-multiline', // export {a,}

// Should only be enabled when linting ECMAScript 2017 (ES8) or higher
'functions': 'ignore', // (function(a,){ })(b,)
// Should only be enabled when linting ECMAScript 2017 (ES8) or higher
'functions': 'ignore', // (function(a,){ })(b,)

'imports': 'always-multiline', // import {a,} from "foo"
'objects': 'always-multiline', // let {a,} = {a: 1}
}],

'imports': 'always-multiline', // import {a,} from "foo"
'objects': 'always-multiline', // let {a,} = {a: 1}
}],
// Enforces at least one newline at the end of non-empty files
'eol-last': ['error', 'always'],

// Consistent indentation style
'indent': [
'error', 2, {
// Indent case clauses with 2 spaces with respect to switch statements
SwitchCase: 1,
}],

// Consistent line endings independent of operating system, VCS, or editor used across your codebase (default: unix)
'linebreak-style': ['error', 'unix'],

// Enforce a maximum line length of 120 characters (instead of 80 from Standard) [See pull request #4]
'max-len': ['error', 120],

// Require constructor names to begin with a capital letter
'new-cap': [
'error', {
// Allows specified uppercase-started function names to be called without the new operator
capIsNewExceptions: ['Polymer'],

// Allows any uppercase-started function names that match the specified regex pattern to be called without the
// new operator
capIsNewExceptionPattern: '^(UdeS|Polymer)',
}],
// Disallow trailing spaces at the end of lines
'no-trailing-spaces': 'error',

// Disallow the use of console [See pull request #2]
'no-console': 'warn',

// Require JSDoc comments
'require-jsdoc': [
'error', {
// Requires JSDoc comments for the specified nodes
'require': {
// Class Foo
'ClassDeclaration': true,

// function foo() {}
'FunctionDeclaration': true,

// constructor() {} [See pull request #1]
'MethodDefinition': false,
},
},
],

// Enforce valid JSDoc comments
'valid-jsdoc': ['error', {
// If and only if the function or method has a return statement [See pull request #1]
requireReturn: false,
}],
},
// enforce consistent spacing inside braces
'object-curly-spacing': ['error', 'always'],

// Override from Google
// https://github.com/google/eslint-config-google/blob/394bf3c9f858b83514fdcbf23d74492e253d611f/index.js#L269-L275
'require-jsdoc': 'off',

// Variables that are accessed but not defined within the same file
globals: {
// UdeS components and global scoped variables
UdeS: true,
// Require or disallow semicolons instead of ASI
'semi': ['error', 'always'],

// UdeS components and global scoped variables
Polymer: true,
// Override from Google
// https://github.com/google/eslint-config-google/blob/394bf3c9f858b83514fdcbf23d74492e253d611f/index.js#L65-L70
'valid-jsdoc': 'off',
},
}
};
24 changes: 24 additions & 0 deletions node-8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
// Extends the UdeS ESLint config
extends: [
'./index.js',
],

// Supported JavaScript language options
parserOptions: {
// Enables ES8/ES2017 syntax
ecmaVersion: 8,

// Code is in ECMAScript modules (default: script)
sourceType: 'module',
},

// Defines global variables that are predefined
env: {
// Enable ES6 features (automatically sets the ecmaVersion parser option to 6)
es6: true,

// Node.js global variables and Node.js scoping
node: true,
},
};
Loading

0 comments on commit bf56d5f

Please sign in to comment.