From ec845e5e7fe3a9fb7b106c791cded2a283ebe42d Mon Sep 17 00:00:00 2001 From: Vitaly Kramskikh Date: Mon, 25 Jul 2016 17:52:13 +0300 Subject: [PATCH] Added config with ES2015-only rules This commit adds an additional config, which should be used in ES2015-based projects. It's available by adding `extends: openstack/es2015` to project's .eslintrc file. Change-Id: I5d54cdceb206db7a52ee396eafc513b290e38f86 --- .eslintrc-es2015 | 28 ++++++++++++++++++++++++++++ README.md | 9 +++++---- es2015.js | 22 ++++++++++++++++++++++ index.js | 15 +-------------- load-config.js | 31 +++++++++++++++++++++++++++++++ package.json | 3 +++ 6 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 .eslintrc-es2015 create mode 100644 es2015.js create mode 100644 load-config.js diff --git a/.eslintrc-es2015 b/.eslintrc-es2015 new file mode 100644 index 0000000..2908e3b --- /dev/null +++ b/.eslintrc-es2015 @@ -0,0 +1,28 @@ +# This file contains rules which should only be enabled in +# ES2015-based projects. +extends: openstack + +parserOptions: + ecmaVersion: 6 + sourceType: module + +rules: + # disallow unnecessary .call() and .apply() + # http://eslint.org/docs/rules/no-useless-call + no-useless-call: 2 + + # require let or const instead of var + # http://eslint.org/docs/rules/no-var + no-var: 2 + + # suggest using arrow functions as callbacks + # http://eslint.org/docs/rules/prefer-arrow-callback + prefer-arrow-callback: 2 + + # suggest using the spread operator instead of .apply(). + # http://eslint.org/docs/rules/prefer-spread + prefer-spread: 2 + + # suggest using the rest parameters instead of arguments + # http://eslint.org/docs/rules/prefer-rest-params + prefer-rest-params: 2 diff --git a/README.md b/README.md index 30dce4e..5a77f65 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ project to stay as close to the common guidelines as possible. To add these rules to your project, follow these steps. 1. `npm install --save-dev eslint eslint-config-openstack` -2. Add `extends: "openstack"` to your `.eslintrc` yaml file +2. Add `extends: "openstack"` to your `.eslintrc` yaml file. If your project is using ES2015, add + `extends: "openstack/es2015"` instead. ## Approval Policies @@ -29,11 +30,11 @@ Patches that upgrade eslint only require two core approvers to land. These patch upstream rules in a deactivated state, and delete any deprecated rules. #### Policy upgrades require all cores -Updates to policies and governance on this project require +2 votes from all direct cores on the +Updates to policies and governance on this project require +2 votes from all direct cores on the project. Core votes from the parent OpenStack QA project are optional. #### Patches should be abandoned after a month of inactivity Cores should attempt to keep the list of extant patches small and managable. As such, they should -talk to any author whose patch has failed to garner the necessary support, and has experienced -one month of inactivity. Reasonable notice should be given to the author before a patch is +talk to any author whose patch has failed to garner the necessary support, and has experienced +one month of inactivity. Reasonable notice should be given to the author before a patch is abandoned. diff --git a/es2015.js b/es2015.js new file mode 100644 index 0000000..d8be3f1 --- /dev/null +++ b/es2015.js @@ -0,0 +1,22 @@ +/* + * Copyright 2016 Mirantis, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. +**/ + +/** + * The default module for this package simply reads in the .eslintrc-es2015 yaml file, and returns + * it as a module. + */ + +module.exports = require('./load-config')('.eslintrc-es2015'); diff --git a/index.js b/index.js index bba9cd6..6c52d16 100644 --- a/index.js +++ b/index.js @@ -14,22 +14,9 @@ * under the License. */ -/*eslint-disable strict*/ -'use strict'; -/*eslint-enable strict*/ - /** * The default module for this package simply reads in the .eslintrc yaml file, and returns it * as a module. */ -var yaml = require('js-yaml'); -var fs = require('fs'); -var path = require('path'); - -/*eslint-disable no-sync */ -var rcPath = path.join(__dirname, '.eslintrc'); -var fileContent = fs.readFileSync(rcPath); -/*eslint-enable no-sync */ - -module.exports = yaml.safeLoad(fileContent); +module.exports = require('./load-config')('.eslintrc'); diff --git a/load-config.js b/load-config.js new file mode 100644 index 0000000..ec05157 --- /dev/null +++ b/load-config.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the 'License'); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/** + * This is a helper module used to load and export YAML-based ESLint config + */ + +var yaml = require('js-yaml'); +var fs = require('fs'); +var path = require('path'); + +module.exports = function(filename) { + 'use strict'; + + var rcPath = path.join(__dirname, filename); + var fileContent = fs.readFileSync(rcPath); // eslint-disable-line no-sync + return yaml.safeLoad(fileContent); +}; diff --git a/package.json b/package.json index 6232d1a..8fe39c1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "main": "index.js", "files": [ "index.js", + "es2015.js", + "load-config.js", ".eslintrc", + ".eslintrc-es2015", "LICENSE", "README.md" ],