π Pluggable and configurable JavaScript Linter, code transformer and formatter with built-in ESLint and Babel support for js, jsx typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way π
MIT License
Bot releases are visible (Hide)
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
βIf a warrior is not unattached to life and death, he will be of no use whatsoever. The saying that βAll abilities come from one mindβ sounds as though it has to do with sentient matters, but it is in fact a matter of being unattached to life and death. With such non-attachment one can accomplish any feat.β
β Yamamoto Tsunetomo, Hagakure: The Book of the Samurai
Hi folks, the time is come for next major release of πPutout.
The changes are small, but important:
@putout/plugin-declare
The name of declare-undefined-variables
was to long and not informative:
constants
and imports
;So it was shorten, please change your .putout.json
, if you disabled or used in any way:
{
"rules": {
- "declare-undefined-variables": "off" ,
+ "declare": "off",
}
}
Such useful plugin can declare variables for you on top of a file when you use it,
so you better keep it on ;).
For example if you use:
assign(obj, {
hello: 'world',
});
@putout/plugin-declare
will transform it to:
const {assign} = Object;
assign(obj, {
hello: 'world',
});
Ability to declare variable becomes so simple because of @putout/operator-declare
:
const {operator} = require('putout');
const {declare} = operator;
module.exports = declare({
readFile: `import {readFile} from 'fs/promises'`,
});
You can even declare any variable you need in your project adding couple lines to .putout.json
:
{
"rules": {
"putout/declare": ["on", {
"declarations": {
"fs": "import fs from 'fs/promises'"
}
}]
}
}
You can also use a new type of plugin Declarator
, in this case code will be even simpler (checkout in πPutout Editor):
module.exports.declare = () => ({
readFile: `import {readFile} from 'fs/promises'`,
});
putout/apply-declare
from @putout/plugin-putout
will help you migrate to a new plugin type.
There is also rules that benefits from this feature in a couple other plugins:
You can do even more with putout/evaluate
ESLint rule:
-import {readFile} from '__putout_evaluate: `./` + basename(__filename).replace(`.spec.js`, `.js`)';
+import {readFile} from './hello.js';
@putout/plugin-maybe
Renamed from @putout/plugin-apply-maybe
.
Please change your .putout.json
, if you disabled or used in any way:
{
"rules": {
- "apply-maybe": "off" ,
+ "maybe": "off",
}
}
@putout/plugin-apply-at
Renamed from @putout/plugin-apply-array-at
, since same method exists not only in prototype
of Array
The
at()
method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.(c) MDN:
Array.prototype.at()
But also in String.prototype
:
The
at()
method takes an integer value and returns a newString
consisting of the single UTF-16 code unit located at the specified offset. This method allows for positive and negative integers. Negative integers count back from the last string character.(c) MDN:
String.prototype.at()
Please change your .putout.json
, if you disabled or used in any way:
{
"rules": {
- "apply-array-at": "off" ,
+ "apply-at": "off",
}
}
@putout/plugin-types
A brand new plugin types
merged to itself part of declare
, and a couple other plugins, so update .putout.json
:
{
"rules": {
- "convert-typeof-to-is-type": "off" ,
- "remove-useless-type-conversions": "off",
- "remove-useless-typeof": "off",
- "apply-is-array": "off",
- "remove-useless-type-conversion/with-double-negations": "off",
+ "types/convert-typeof-to-is-type": "off",
+ "types/remove-useless-conversion": "off",
+ "types/remove-double-negations": "off",
+ "types/remove-useless-typeof": "off",
+ "types/apply-is-array": "off",
+ "types/remove-double-negations": "off"
}
}
@putout/plugin-conditions
A brand new plugin conditions
merged couple other plugins to speed up install, so update .putout.json
:
{
"rules": {
- "apply-comparison-order": "off" ,
- "apply-if-condition": "off",
- "convert-comparison-to-boolean": "off",
- "convert-equal-to-strict-equal": "off",
- "remove-useless-conditions/evaluate": "off",
- "remove-useless-conditions/simplify": "off",
- "convert-comparison-to-boolean": "off",
- "remove-constant-conditions": "off",
- "remove-boolean-from-assertions": "off",
+ "conditions/apply-comparison-order": "off",
+ "conditions/apply-if": "off",
+ "conditions/convert-comparison-to-boolean": "off",
+ "conditions/convert-equal-to-strict-equal": "off",
+ "conditions/evaluate": "off"
+ "conditions/simplify": "off",
+ "conditions/convert-comparison-to-boolean": "off",
+ "conditions/remove-constant": "off",
+ "conditions/remove-boolean": "off"
}
}
@putout/plugin-for-of
A brand new plugin for-of
merged couple other plugins to speed up install, so update .putout.json
:
{
"rules": {
- "convert-for-for-of": "off" ,
- "convert-for-each-for-of": "off",
- "convert-for-in-to-for-of": "off",
- "convert-map-to-for-of": "off",
- "remove-useless-for-of": "off",
- "remove-unused-for-of-variables": "off",
- "remove-useless-array-from": "off",
- "remove-useless-variables/for-of": "off"
- "convert-reduce-to-for-of": "off",
+ "for-of/for": "off",
+ "for-of/for-each": "off",
+ "for-of/for-in": "off",
+ "for-of/map": "off",
+ "for-of/remove-useless": "off"
+ "for-of/remove-unused-variables": "off",
+ "for-of/remove-useless-array-from": "off",
+ "for-of/remove-useless-variables": "off",
+ "for-of/reduce": "off"
}
}
eslint-plugin-putout v17
Update ESLint plugin, to have support of for-of
rules π.
@putout/plugin-package-json
With release of πWisdom v14 commitType
defaults to colon
so there is no need to set it if it OK for you it was colon
rule package-json/remove-commit-type
handles such cases π. So we have less bytes to download while install π.
Here is package.json
:
{
"name: "putout",
"version": "29.0.0",
- "commitType": "colon"
}
Same with nupdate v11
it uses colon
by default.
Now you have ability to define printer
you want, it can be:
If you want to try brand new @putout/printer
update .putout.json
with:
{
"printer": "putout"
}
When you need to customize options, use:
{
"printer": ["putout", {
"format": {
"indent": " "
}
}]
}
Same with tests:
const test = require('@putout/test');
const rm = require('..');
const test = createTest({
printer: "putout",
plugins: [
['remove-unused-variables', rm],
]
});
New printer is:
About speed, for file speed.js
:
const putout = require('putout');
const {readFileSync} = require('fs');
const parser = require('@babel/parser');
const code = readFileSync('./lib/tokenize/tokenize.js', 'utf8');
const ast = parser.parse(code);
speed('recast');
speed('putout');
function speed(printer) {
console.time(printer);
for (let i = 0; i < 1000; i++) {
putout(code, {
printer,
plugins: [
'remove-unused-variables',
],
});
}
console.timeEnd(printer);
}
With contents of tokenize.js
from @putout/printer
, we have:
That's all for for now, have a good day π¦!
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
const a = b.a || c -> const {a = c} = b
since it works only for b.a = undefined
not for: 0, null, undefined, '', etcPublished by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago
Published by coderaiser over 1 year ago