Skip to content

Commit

Permalink
Vendor eslint-plugin-self
Browse files Browse the repository at this point in the history
  • Loading branch information
Standard8 authored and azeemba committed May 19, 2024
1 parent 693788e commit 4a4e557
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 110 deletions.
234 changes: 125 additions & 109 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-self": "^1.2.1",
"eslint-plugin-self": "file:vendor/eslint-plugin-self",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"prettier": "^2.3.2"
Expand Down
20 changes: 20 additions & 0 deletions vendor/eslint-plugin-self/CHANGELOG.md
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))


25 changes: 25 additions & 0 deletions vendor/eslint-plugin-self/LICENSE.md
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.
41 changes: 41 additions & 0 deletions vendor/eslint-plugin-self/README.md
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"
]
}
```
57 changes: 57 additions & 0 deletions vendor/eslint-plugin-self/index.js
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;
27 changes: 27 additions & 0 deletions vendor/eslint-plugin-self/package.json
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"
}
}

0 comments on commit 4a4e557

Please sign in to comment.