Skip to content

Commit

Permalink
feature(@putout/plugin-convert-index-of-to-includes) add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 1, 2020
1 parent da9d4b4 commit 6175190
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/plugin-convert-index-of-to-includes/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"plugin:putout/recommended",
"plugin:node/recommended"
],
"plugins": [
"putout",
"node"
]
}
6 changes: 6 additions & 0 deletions packages/plugin-convert-index-of-to-includes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.nyc_output
legacy
*.swp
yarn-error.log

13 changes: 13 additions & 0 deletions packages/plugin-convert-index-of-to-includes/.madrun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const {run} = require('madrun');

module.exports = {
'test': () => `tape 'test/*.js'`,
'watch:test': () => `nodemon -w lib -w test -x ${run('test')}`,
'lint': () => `putout lib test .madrun.js`,
'fix:lint': () => run('lint', '--fix'),
'coverage': () => `nyc ${run('test')}`,
'report': () => `nyc report --reporter=text-lcov | coveralls || true`,
};

5 changes: 5 additions & 0 deletions packages/plugin-convert-index-of-to-includes/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*
test
yarn-error.log

madrun.js
21 changes: 21 additions & 0 deletions packages/plugin-convert-index-of-to-includes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) coderaiser

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.
56 changes: 56 additions & 0 deletions packages/plugin-convert-index-of-to-includes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# putout-plugin-convert-apply-to-spread [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]

[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-convert-apply-to-spread.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-convert-apply-to-spread "npm"

[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-convert-apply-to-spread
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-convert-apply-to-spread

`putout` plugin adds ability to convert `apply` to `spread`.
## Install

```
npm i @putout/plugin-convert-apply-to-spread -D
```

## Rule

Rule `convert-apply-to-spread` is enabled by default, to disable add to `.putout.json`:

```json
{
"rules": {
"convert-apply-to-spread": false
}
}
```

## Code Example

```js
const {readFileSync} = require('fs');
const source = readFileSync('./1.js', 'utf8');

const putout = require('putout');

console.log(source);
// outputs
`
console.log.apply(console, arguments);
`

const result = putout(source, {
plugins: [
'convert-apply-to-spread'
]
});
// returns
`
console.log(...arguments);
`
```

## License

MIT

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports.report = () => '"[].includes" should be used instead of "!~[].indexOf"';

module.exports.replace = () => ({
'!~__a.indexOf(__b)': '__a.includes(__b)',
});

51 changes: 51 additions & 0 deletions packages/plugin-convert-index-of-to-includes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@putout/plugin-convert-index-of-to-includes",
"version": "1.0.0",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "putout plugin adds ability to convert indexOf to includes",
"homepage": "http://github.com/coderaiser/putout",
"main": "lib/convert-index-of-to-includes.js",
"release": false,
"tag": false,
"changelog": false,
"repository": {
"type": "git",
"url": "git://github.com/coderaiser/putout.git"
},
"scripts": {
"test": "madrun test",
"lint": "madrun lint",
"fix:lint": "madrun fix:lint",
"coverage": "madrun coverage"
},
"dependencies": {},
"keywords": [
"putout",
"putout-plugin",
"putout-plugin-convert",
"plugin",
"convert",
"index-of",
"includes"
],
"devDependencies": {
"@putout/test": "^2.0.0",
"coveralls": "^3.0.0",
"eslint": "^7.1.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-putout": "^4.0.0",
"madrun": "^6.0.0",
"nyc": "^15.0.1",
"supertape": "^2.0.0"
},
"peerDependencies": {
"putout": ">=8"
},
"license": "MIT",
"engines": {
"node": ">=8.3.0"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const test = require('@putout/test')(__dirname, {
'convert-index-of-to-includes': require('..'),
});

test('plugin-convert-index-of-to-includes: report', (t) => {
t.report('index-of', '"[].includes" should be used instead of "!~[].indexOf"');
t.end();
});

test('plugin-convert-index-of-to-includes: transform', (t) => {
t.transform('index-of');
t.end();
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if (array.includes(a)) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if (array.includes(a)) {
}

0 comments on commit 6175190

Please sign in to comment.