{"name":"@putout/plugin-new","version":"2.1.0","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin adds ability to remove useless and add missing operator 'new'","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-new#readme","main":"lib/index.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git://github.com/coderaiser/putout.git"},"scripts":{"publishOnly":"madrun publishOnly","test":"madrun test","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report"},"dependencies":{},"keywords":["putout","putout-plugin","plugin","new","useless","missing"],"devDependencies":{"@putout/test":"^6.0.0","c8":"^7.5.0","eslint":"^8.0.1","eslint-plugin-n":"^16.0.0","madrun":"^9.0.0"},"peerDependencies":{"putout":">=29"},"license":"MIT","engines":{"node":">=16"},"publishConfig":{"access":"public"},"gitHead":"9b6199884930b02238018ed0c2124b1b2cece4c7","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_id":"@putout/plugin-new@2.1.0","_nodeVersion":"18.16.0","_npmVersion":"9.6.6","dist":{"integrity":"sha512-gAzSOLQ3Jo2nhMhJfdGRWwREJMj3v1v8fx7vTMMRx3GJGpEQ+42ibdvPblvJ10+dV2O9//KLDlahzlT8R3on/A==","shasum":"eb2b4167ec1c3a9efbae86466ef8d7b444dbbd1f","tarball":"http://registry-npm.ywwl.com/@putout/plugin-new/download/@putout/plugin-new-2.1.0.tgz","fileCount":6,"unpackedSize":7356,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG4e3RHTRsEqjgKwsfE3Ixje2Stt8JqnWwW8GVoPLILKAiEAtnwk52CeQJNDfRnck1+8kfIwDvn2dJzBbtvlK3s01+8="}],"size":2945,"noattachment":false,"key":"/@putout/plugin-new/-/@putout/plugin-new-2.1.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/plugin-new_2.1.0_1685651083680_0.751193072278868"},"_hasShrinkwrap":false,"readme":"# @putout/plugin-new [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-new.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-new \"npm\"\n\n> The `new` operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to add missing and remove useless operator `new`.\n\n## Install\n\n```\nnpm i @putout/plugin-new\n```\n\n## Rule\n\n```json\n{\n    \"rules\": {\n        \"new/remove-useless\": \"on\",\n        \"new/add-missing\": \"on\"\n    }\n}\n```\n\n## remove-useless\n\nOperator `new` has no sense for `Boolean`, `String`, `Number`, `Object`, `RegExp`, `Math`, `Reflect`, `Error`, `TypeError`:\n\n> Thus the function call `Error(…)` is equivalent to the object creation expression `new Error(…)` with the same arguments.\n>\n> (c) https://262.ecma-international.org/12.0/#sec-error-constructor\n\nAnd [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) cannot be used with `new`, as it is primitive.\n\n### ❌ Example of incorrect code\n\n```js\nnew Error('Something whent wrong');\nnew new Boolean()();\n```\n\n### ✅ Example of correct code\n\n```js\nError('Something whent wrong');\nBoolean();\n```\n\n## add-missing\n\n> The `Set` constructor lets you create Set objects that store unique values of any type, whether primitive values or object references.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set)\n\nMissing operator `new` should be added since built-in objects:\n\n- `Set`;\n- `WeakSet`;\n- `Map`;\n- `WeakMap`;\n- `Int8Array`;\n- `Uint8Array`;\n- `Uint8ClampedArray`;\n- `Int16Array`;\n- `Uint16Array`;\n- `Int32Array`;\n- `Uint32Array`;\n- `Float32Array`;\n- `Float64Array`;\n- `BigInt64Array`;\n- `BigUint64Array`;\n\nProduces [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) when called without `new`:\n\n```\nUncaught TypeError: Constructor Set requires 'new'\n```\n\n### ❌ Example of incorrect code\n\n```js\nconst map = Map();\n```\n\n### ✅ Example of correct code\n\n```js\nconst map = new Map();\n```\n\n## Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`remove-useless-new`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-new#readme)| ✅\n⏣ **ESLint** | [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers) | ❌\n⠀| [`no-new-object`](https://eslint.org/docs/rules/no-new-object) | ❌\n⠀| [`no-array-constructor`](https://eslint.org/docs/rules/no-array-constructor) | ❌\n⠀| [`no-new-symbol`](https://eslint.org/docs/rules/no-new-symbol) | ❌\n⠀| [`no-new-native-constructor`](https://eslint.org/docs/rules/https://eslint.org/docs/latest/rules/no-new-native-nonconstructor) | ❌\n\n## License\n\nMIT\n","publish_time":1685651083922,"_cnpm_publish_time":1685651083922,"dist-tags":{"latest":"5.1.0"}}