-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
296 additions
and
110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
|
||
## v1.2.1 (2020-05-27) | ||
|
||
* Support overrides having no rules :see_no_evil: ([#5](https://github.com/not-an-aardvark/eslint-plugin-self/issues/5)) ([e266543](https://github.com/not-an-aardvark/eslint-plugin-self/commit/e266543e50d062251755dd488abae31be7644bb1)) | ||
|
||
## v1.2.0 (2019-03-04) | ||
|
||
* Support redefining plugins, overrides and rules with a "/" in them ([#2](https://github.com/not-an-aardvark/eslint-plugin-self/issues/2)) ([428664e](https://github.com/not-an-aardvark/eslint-plugin-self/commit/428664e1cf8f3726e0bb3b10bb3e137d271749c2)) | ||
|
||
## v1.1.0 (2018-07-06) | ||
|
||
* Chore: add release script ([983a7d0](https://github.com/not-an-aardvark/eslint-plugin-self/commit/983a7d05c48bccc125f8d89fae1109a0c5a1d670)) | ||
* Update: Add support for @scoped packages ([#1](https://github.com/not-an-aardvark/eslint-plugin-self/issues/1)) ([c57a01b](https://github.com/not-an-aardvark/eslint-plugin-self/commit/c57a01bbf922b82d09a0cceba6b5e845fab7d23a)) | ||
|
||
## v1.0.1 (2017-07-02) | ||
|
||
* Fix: transform references to own rules in configs to use `self` prefix ([2dce85e](https://github.com/not-an-aardvark/eslint-plugin-self/commit/2dce85e445a7604f5fd963d1366509fa7a66d420)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
The MIT License (MIT) | ||
===================== | ||
|
||
Copyright © 2017 Teddy Katz | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# eslint-plugin-self | ||
|
||
When writing an ESLint plugin, it's often useful to use the plugin's rules to lint the plugin's own codebase. You can use `eslint-plugin-self` to do that. | ||
|
||
## Usage | ||
|
||
``` | ||
npm install eslint-plugin-self --save-dev | ||
``` | ||
|
||
Note: `eslint-plugin-self` must be installed locally (it will not work if installed globally), and the project that installs it must be a functioning ESLint plugin. | ||
|
||
Add the following to your config file: | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
"self" | ||
] | ||
} | ||
``` | ||
|
||
Then you can use your plugin's rules, with the `self/` prefix: | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"self/my-custom-rule": "error" | ||
} | ||
} | ||
``` | ||
|
||
You can also use your plugin's configs, or anything else exported by your plugin: | ||
|
||
```json | ||
{ | ||
"extends": [ | ||
"plugin:self/some-config" | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const plugin = require('../..'); | ||
const selfPlugin = Object.assign({}, plugin); | ||
|
||
const pkgName = require('../../package.json').name; | ||
let pluginName; | ||
if (pkgName[0] === "@") { | ||
const matches = pkgName.match(/^(@[^/]+)\/eslint-plugin(?:-(.*))?$/); | ||
pluginName = matches.slice(1, 3).filter(Boolean).join('/'); | ||
} else { | ||
pluginName = pkgName.replace(/^eslint-plugin-/, ''); | ||
} | ||
|
||
function createRuleset(rules) { | ||
return Object.keys(rules).reduce((newRules, oldRuleName) => { | ||
const newRuleName = oldRuleName.startsWith(`${pluginName}/`) | ||
? `self${oldRuleName.slice(oldRuleName.indexOf('/'))}` | ||
: oldRuleName; | ||
|
||
newRules[newRuleName] = rules[oldRuleName]; | ||
return newRules; | ||
}, {}); | ||
} | ||
|
||
if (plugin.configs) { | ||
selfPlugin.configs = Object.assign({}, plugin.configs); | ||
|
||
Object.keys(plugin.configs).forEach(configName => { | ||
const config = plugin.configs[configName]; | ||
selfPlugin.configs[configName] = Object.assign({}, config); | ||
if (config.extends) { | ||
selfPlugin.configs[configName].extends = [].concat(config.extends) | ||
.map(extendsName => extendsName.replace(`plugin:${pluginName}/`, 'plugin:self/')); | ||
} | ||
if (config.plugins) { | ||
selfPlugin.configs[configName].plugins = [].concat(config.plugins) | ||
.map(enabledPluginName => enabledPluginName.replace(pluginName, 'self')); | ||
} | ||
if (config.rules) { | ||
selfPlugin.configs[configName].rules = createRuleset(config.rules); | ||
} | ||
if (config.overrides) { | ||
selfPlugin.configs[configName].overrides = [].concat(config.overrides) | ||
.map((override) => { | ||
if (!override.rules) return override; | ||
return Object.assign( | ||
{}, | ||
override, | ||
{rules: createRuleset(override.rules)} | ||
); | ||
}) | ||
} | ||
}); | ||
} | ||
|
||
module.exports = selfPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "eslint-plugin-self", | ||
"version": "1.2.1", | ||
"description": "Allows ESLint plugins to be run on themselves", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"generate-release": "node-release-script" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/not-an-aardvark/eslint-plugin-self.git" | ||
}, | ||
"keywords": [ | ||
"eslint-plugin", | ||
"eslintplugin" | ||
], | ||
"author": "Teddy Katz", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/not-an-aardvark/eslint-plugin-self/issues" | ||
}, | ||
"homepage": "https://github.com/not-an-aardvark/eslint-plugin-self#readme", | ||
"devDependencies": { | ||
"@not-an-aardvark/node-release-script": "^0.1.0" | ||
} | ||
} |