Skip to content

Commit 0179a6f

Browse files
committed
feature: putout: @putout/plugin-remove-useless-delete: add
1 parent c620fc0 commit 0179a6f

17 files changed

Lines changed: 263 additions & 0 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ It has a lot of plugins divided by groups:
21452145
| [`@putout/plugin-remove-useless-arguments`](/packages/plugin-remove-useless-arguments#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-useless-arguments.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-useless-arguments) |
21462146
| [`@putout/plugin-remove-useless-escape`](/packages/plugin-remove-useless-escape#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-useless-escape.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-useless-escape) |
21472147
| [`@putout/plugin-remove-useless-template-expressions`](/packages/plugin-remove-useless-template-expressions#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-useless-template-expressions.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-useless-template-expressions) |
2148+
| [`@putout/plugin-remove-useless-delete`](/packages/plugin-remove-useless-delete#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-useless-delete.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-useless-delete) |
21482149
| [`@putout/plugin-remove-debugger`](/packages/plugin-remove-debugger#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-debugger.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-debugger) |
21492150
| [`@putout/plugin-remove-iife`](/packages/plugin-remove-iife#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-iife.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-iife) |
21502151
| [`@putout/plugin-remove-unreachable-code`](/packages/plugin-remove-unreachable-code#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-remove-unreachable-code.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-remove-unreachable-code) |

docs/syntax-errors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ readFile('./hello.js', 'utf8');
114114

115115
</details>
116116

117+
<details><summary>remove useless<code>delete</code></summary>
118+
119+
```diff
120+
-delete abc;
121+
```
122+
123+
</details>
124+
117125
<details><summary>remove getter arguments</summary>
118126

119127
```diff
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'publishOnly': () => run('lint'),
5+
'test': () => `tape 'test/*.js'`,
6+
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
7+
'lint': () => `putout .`,
8+
'fresh:lint': () => run('lint', '--fresh'),
9+
'lint:fresh': () => run('lint', '--fresh'),
10+
'fix:lint': () => run('lint', '--fix'),
11+
'coverage': async () => `c8 ${await run('test')}`,
12+
'report': () => 'c8 report --reporter=lcov',
13+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.*
2+
test
3+
yarn-error.log
4+
5+
coverage
6+
*.config.*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printer": "putout",
3+
"match": {
4+
"*.md": {
5+
"remove-useless-delete": "off"
6+
}
7+
}
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# @putout/plugin-remove-useless-delete [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-remove-useless-assign.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-remove-useless-assign "npm"
5+
6+
> The `delete` operator removes a `property` from an `object`. If the `property`'s value is an `object` and there are no more references to the `object`, the `object` held by that `property` is eventually released automatically.
7+
>
8+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete)
9+
10+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to remove useless `delete`.
11+
Check it out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/71a95e8831318c77549ae2e49332f6a4/32dd1c3525ba8b65be2cf7fd02cb8e20646ac3f8).
12+
13+
Fixes syntax error:
14+
15+
> `SyntaxError: Delete of an unqualified identifier in strict mode.`
16+
>
17+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Delete_in_strict_mode)
18+
19+
## Install
20+
21+
```
22+
npm i @putout/plugin-remove-useless-delete
23+
```
24+
25+
## Rule
26+
27+
```json
28+
{
29+
"rules": {
30+
"remove-useless-assign": "on"
31+
}
32+
}
33+
```
34+
35+
## ❌ Example of incorrect code
36+
37+
```js
38+
delete x;
39+
delete x.x;
40+
delete x[1];
41+
```
42+
43+
## ✅ Example of correct code
44+
45+
```js
46+
delete x.x;
47+
delete x[1];
48+
```
49+
50+
## Comparison
51+
52+
Linter | Rule | Fix
53+
--------|-------|------------|
54+
🐊 **Putout** | [`remove-useless-delete`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useles-delete#readme) | ✅
55+
**ESLint** | [`no-delete-var`](https://eslint.org/docs/rules/no-delete-var) | ❌
56+
57+
## License
58+
59+
MIT
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const {safeAlign} = require('eslint-plugin-putout/config');
4+
5+
module.exports = [
6+
...safeAlign, {
7+
files: ['*.md{js}'],
8+
languageOptions: {
9+
ecmaVersion: 3,
10+
sourceType: 'script',
11+
parserOptions: {
12+
babelOptions: {
13+
sourceType: 'script',
14+
},
15+
},
16+
},
17+
},
18+
];

0 commit comments

Comments
 (0)