diff --git a/packages/plugin-convert-index-of-to-includes/.eslintrc.json b/packages/plugin-convert-index-of-to-includes/.eslintrc.json new file mode 100644 index 0000000000..aa14888027 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/.eslintrc.json @@ -0,0 +1,10 @@ +{ + "extends": [ + "plugin:putout/recommended", + "plugin:node/recommended" + ], + "plugins": [ + "putout", + "node" + ] +} diff --git a/packages/plugin-convert-index-of-to-includes/.gitignore b/packages/plugin-convert-index-of-to-includes/.gitignore new file mode 100644 index 0000000000..d4a059dc5e --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/.gitignore @@ -0,0 +1,6 @@ +node_modules +.nyc_output +legacy +*.swp +yarn-error.log + diff --git a/packages/plugin-convert-index-of-to-includes/.madrun.js b/packages/plugin-convert-index-of-to-includes/.madrun.js new file mode 100644 index 0000000000..61378b3cfc --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/.madrun.js @@ -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`, +}; + diff --git a/packages/plugin-convert-index-of-to-includes/.npmignore b/packages/plugin-convert-index-of-to-includes/.npmignore new file mode 100644 index 0000000000..1601608026 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/.npmignore @@ -0,0 +1,5 @@ +.* +test +yarn-error.log + +madrun.js diff --git a/packages/plugin-convert-index-of-to-includes/LICENSE b/packages/plugin-convert-index-of-to-includes/LICENSE new file mode 100644 index 0000000000..eaec9a10f8 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/LICENSE @@ -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. diff --git a/packages/plugin-convert-index-of-to-includes/README.md b/packages/plugin-convert-index-of-to-includes/README.md new file mode 100644 index 0000000000..e321fa91f2 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/README.md @@ -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 + diff --git a/packages/plugin-convert-index-of-to-includes/lib/convert-index-of-to-includes.js b/packages/plugin-convert-index-of-to-includes/lib/convert-index-of-to-includes.js new file mode 100644 index 0000000000..b82a32ca64 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/lib/convert-index-of-to-includes.js @@ -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)', +}); + diff --git a/packages/plugin-convert-index-of-to-includes/package.json b/packages/plugin-convert-index-of-to-includes/package.json new file mode 100644 index 0000000000..fb2d9b3b72 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/package.json @@ -0,0 +1,51 @@ +{ + "name": "@putout/plugin-convert-index-of-to-includes", + "version": "1.0.0", + "author": "coderaiser (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" + } +} diff --git a/packages/plugin-convert-index-of-to-includes/test/convert-index-of-to-inludes.js b/packages/plugin-convert-index-of-to-includes/test/convert-index-of-to-inludes.js new file mode 100644 index 0000000000..5aab952f40 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/test/convert-index-of-to-inludes.js @@ -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(); +}); + diff --git a/packages/plugin-convert-index-of-to-includes/test/fixture/index-of-fix.js b/packages/plugin-convert-index-of-to-includes/test/fixture/index-of-fix.js new file mode 100644 index 0000000000..0dcf8737e0 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/test/fixture/index-of-fix.js @@ -0,0 +1,2 @@ +if (array.includes(a)) { +} diff --git a/packages/plugin-convert-index-of-to-includes/test/fixture/index-of.js b/packages/plugin-convert-index-of-to-includes/test/fixture/index-of.js new file mode 100644 index 0000000000..0dcf8737e0 --- /dev/null +++ b/packages/plugin-convert-index-of-to-includes/test/fixture/index-of.js @@ -0,0 +1,2 @@ +if (array.includes(a)) { +}