π 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
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
remove-useless-constructor
added πWrapper classes have surprising behaviour, such as
new Boolean(false)
evaluating totrue
.https://google.github.io/styleguide/tsguide.html#primitive-types-wrapper-classes
New putout
plugin adds ability to remove useless constructors
. Use it with remove-useless-new to get event more benefit π₯.
const s = String('hello');
const b = Boolean(false);
const n = Number(5);
const s = 'hello';
const b = false;
const n = 5;
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Usually I don't write release notes for patch
releases, but the case of today is unusual.
patch
if so much changes?That's simple, because this release has only one change of putout
core, and this is a fix of a bug related to converting ESM
to CommonJS
and vice versa, which are enabled by default for some time π.
To the point! When there is no .putout.json
file but there is package.json
with type=module
rule convert-commonjs-to-esm
was disabled (!). But it should not so it was a bug π which is proudly fixed with https://github.com/coderaiser/putout/commit/4121ffabac657ae1d42f7e27e89aac03b79dd70f.
Adding new rules never was a major
change, especially when plugin added for a long time, and rules
are small, but very useful addition. So @putout/plugin-tape
made for supertape
, mock-import
and overall writing tests more pleasant, has a couple new gamers π₯:
convert-deep-equal-to-equal
Use equal
when comparing with primitives, deepEqual
for Objects
and Arrays
;
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
t.deepEqual(x, 5);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
t.equal(x, 5);
t.end();
});
convert-equal-to-called-once
No need to use equal
, supertape
supports calledOnce
.
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.equal(fn.callCount, 1);
t.end();
});
const test = require('supertape');
const {stub} = test;
test('some message', (t) => {
const fn = stub();
fn();
t.calledOnce(fn);
t.end();
});
add-stop-all
When you write test mocking ESM
with mockImport()
never forget to call stopAll()
when you no longer need it. This leads to bugs in tests which are hard to find, each test should be checked with the one which pass when called alone but fail when called with others.
test('stop-all: should be called', () => {
mockImport('fs/promises', {
readFile: stub(),
});
t.end();
});
test('stop-all: should be called', () => {
mockImport('fs/promises', {
readFile: stub(),
});
stopAll();
t.end();
});
There was also plenty of fixes and improvements of plugins, more info hereπ.
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
t.transform()
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Hi folks! Conversion between ESM
and CommonJS
package systems became simpler then ever π
βThere is surely nothing other than the single purpose of the present moment. A manβs whole life is a succession of moment after moment. If one fully understands the present moment, there will be nothing else to do, and nothing else to pursue. Live being true to the single purpose of the moment.β
(c) Yamamoto Tsunetomo "Hagakure"
While reading options putout
checks package type and if it's empty or commonjs
it enables @putout/plugin-convert-esm-to-commonjs
. If type=module
putout
enables @putout/plugin-convert-commonjs-to-esm
for *.js
files.
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
βGrown-ups never understand anything by themselves, and it is tiresome for children to be always and forever explaining things to themβ.
(c) Antoine de Saint-ExupΓ©ry
A little bit magic from @egilll and now we have Applying a single rule chapter and putout --help
looks this way π :
Usage: putout [options] [path]
Options:
-h, --help display this help and exit
-v, --version output version information and exit
-f, --format [formatter] use a specific output format, the default is: 'progress-bar' localy and 'dump' on CI
-s, --staged add staged files when in git repository
--fix apply fixes of errors to code
--fix-count [count = 10] count of fixes rounds
--rulesdir use additional rules from directory
--transform [replacer] apply Replacer, for example 'var __a = __b -> const __a = __b', read about Replacer https://git.io/JqcMn
--plugins [plugins list] a comma-separated list of plugins to use
--enable [rule] enable the rule and save it to '.putout.json' walking up parent directories
--disable [rule] disable the rule and save it to '.putout.json' walking up parent directories
--enable-all enable all found rules and save them to '.putout.json' walking up parent directories
--disable-all disable all found rules (set baseline) and save them '.putout.json' walking up parent directories
--match [file name] read .putout.json and convert 'rules' to 'match' using pattern
--flow enable flow
--fresh generate a fresh cache
--no-config avoid reading '.putout.json'
--no-ci disable the CI detection
--no-cache disable the cache
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Hi folks π!
This release has not much breaking changes, but mostly clean up of exports
section of package.json
, clean up of help
, adding peaces of documentation, and improving error handling. More on this belowπ.
Among the maxims on Lord Naoshigeβs wall there was this one: ββMatters of great concern should be treated lightly.β Master lttei commented, βMatters of small concern should be treated seriously.β
(c) Yamamoto Tsunetomo βHagakureβ
putout/lib/parse-options
-> putout/parse-options
in exports
of package.json
Since Visual Code already supports node v14
there is no reason to keep an alias (https://github.com/coderaiser/putout/issues/48).
putout/ide
-> putout/safe
in eslint-plugin-putout
eslint-plugin-putout
preset ide
was renamed to safe
:
{
"extends": [
- "plugin:putout/ide"
+ "plugin:putout/safe"
],
"plugins": [
"putout"
]
}
Do you think that you need to make changes by hand :)? Worry not! Putout
get you covered with @putout/plugin-eslint
rule convert-ide-to-safe π .
From --help
output was removed a couple default options:
--no-flow disable flow (default)
--cache enable cache to speed up processing (default)
Since they do nothing π€·ββοΈ.
There is a bunch of exit codes
used by Putout
internally, the time is came to document all of them, you can find it in section Exit Codes, and import in your code with:
import {OK} from 'putout/exit-codes';
While working with ESTrace @retorquere trap into a problem:
const putout = require('putout')
const fs = require('fs')
async function main() {
const estrace = await import('estrace/plugin');
const source = { code: fs.readFileSync('./hello.js', 'utf-8') }
const {code} = putout(source.code, {
fixCount: 1,
rules: {
'estrace/trace': ['on', {
url: './hello.js',
exclude: [ 'FunctionExpression', 'ArrowFunctionExpression' ]
}],
},
plugins: [
[ 'estrace/trace', estrace ],
],
});
console.log(code)
}
The thing is when plugin used with a name estrace/trace
and the rule has the same name, and the rule is nested, options go's nowhere.
This behavior was fixed, and now putout
throws with:
Error: βοΈRule "estrace/trace" cannot be applied to nested plugin "estrace/trace"
at module.exports (/Users/coderaiser/putout/packages/engine-loader/lib/validate-rules.js:25:23)
at module.exports.loadPlugins (/Users/coderaiser/putout/packages/engine-loader/lib/index.js:84:5)
at transform (/Users/coderaiser/estrace/node_modules/putout/lib/putout.js:93:21)
at module.exports (/Users/coderaiser/estrace/node_modules/putout/lib/putout.js:53:20)
at main (/Users/coderaiser/estrace/1.cjs:7:18)
Fix is changed plugin name to estrace
or changing rule to estrace/trace/trace
.
visitor
provided to Traverser
is not a function
When you forgot to pass a function to Traverser visitor
:
module exports.traverse: () => ({
'async (__a) => __b': 'async ({process}) => __b',
}),
You will see something like this:
βοΈ Looks like provided visitor is not a function: "async ({process}) => __b". More on using Traverser: https://git.io/JqcMn
And even more! @putout/plugin-putout
get you covered with: convert-traverse-to-replace
rule.
So most likely [Replacer
](Traverser was meant to be used:
module exports.replacer: () => ({
'async (__a) => __b': 'async ({process}) => __b',
}),
Now, when you have a typo, or trap on something not obvious, Putout
will not only help you, but also show how it looks like: π
.
coderaiser@localcmd:~/putout/packages$ putout --helo
π Invalid option `--helo`. Perhaps you meant `--help`
@putout/test
That's right, @putout/test
now has examples to all provided API
π .
π
to error messages