๐ 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
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
--fix
cannot be used with Ruler
togglerJust landed additional check of user input when running command to set baseline
disabling all found rules --disable-all
and other ruler options.
Ruler
?When you need to change .putout.json
you can do it not only manually editing the file in an editor, but with help of Ruler
as well.
Ruler can enable one rule with putout --enable convert-commonjs-to-esm
or disable all rules with putout --disable-all
. But it should never be used with --fix
, because it's not clear what should be done. Actually what is done is changes made to .putout.json
but putout
doesn't see them and works with older version of config what can be confusing.
Of course this should be documented. But much better way would be to help user with detailed explanation from used application, so there was no need to read the documentation :).
ruler
can be helpful to me?You may want to convert your CommonJS
module into Ecma Script Modules
. Right now this is a trend started by @sindresorhus.
CommonJS
to ESM
Let's suppose you have a file called index.js
:
const unused = 5;
module.exports = function() {
return promise();
}
async function promise(a) {
return Promise.reject(Error('x'));
}
You want to convert it to ESM, and everything else keep untouched. You can do this with a Ruler
. So you disable all rules that Putout
can find right now.
putout index.js --disable-all
will find next errors:
1:4 error "unused" is defined but never used remove-unused-variables
7:23 error "a" is defined but never used remove-unused-variables
3:0 error Arrow functions should be used convert-to-arrow-function
1:0 error "use strict" directive should be on top of commonjs file strict-mode/add
8:4 error Reject is useless in async functions, use throw instead promises/convert-reject-to-throw
4:11 error Async functions should be called using await promises/add-missing-await
7:0 error Useless async should be avoided promises/remove-useless-async
And create config file .putout.json
with:
{
"rules": {
"remove-unused-variables": "off",
"convert-to-arrow-function": "off",
"strict-mode/add": "off",
"promises/convert-reject-to-throw": "off",
"promises/add-missing-await": "off",
"promises/remove-useless-async": "off"
}
}
Then running putout index.js --enable convert-commonjs-to-esm
will update config with:
{
"rules": {
"remove-unused-variables": "off",
"convert-to-arrow-function": "off",
"strict-mode/add": "off",
"promises/convert-reject-to-throw": "off",
"promises/add-missing-await": "off",
- "promises/remove-useless-async": "off"
+ "promises/remove-useless-async": "off",
+ "convert-commonjs-to-esm": "on"
}
}
Then putout --fix index.js
will do the thing and update index.js
with:
const unused = 5;
export default function() {
return promise();
};
async function promise(a) {
return Promise.reject(Error('x'));
}
So in case of src
directory, it will look like:
putout src --disable-all && putout src --enable convert-commonjs-to-esm && putout src --fix
This command will disable all rules that Putout
can find right now and enable single rule. All Putout
rules made for good and highly suggested to be used, they all enabled in this and all my other repositories. Anyways you can always disable what you don't need.
Happy coding ๐!
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
const __a = require("__b")(__args)
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago
But I will, and the time is came to group all rules related to promises together. And this is a...
But this is for good! Right now Putout
has a lot of rules, and would be a little bit more pleasant to use it if will be less rules, but more categories.
Closer to point, next rules now bundled into @putout/plugin-promises
๐ :
-const show = async () => {
+const show = () => {
console.log('hello');
};
- await await Promise.resolve('hello');
+ await Promise.resolve('hello');
import fs from 'fs';
-(async () => {
- const data = await fs.promises.readFile('hello.txt');
-})();
+const data = await fs.promises.readFile('hello.txt');
All of them enabled by default, if you disabled some of them before consider updating .putout.json
:
{
"rules": {
- "remove-useless-async": "off",
- "remove-useless-await": "off",
- "apply-top-level-await: "off"
+ "promises/remove-useless-async": "off",
+ "promises/remove-useless-await": "off",
+ "promises/apply-top-level-await": "off"
},
"plugins": [
- "remove-useless-async",
- "remove-useless-await",
- "apply-top-level-await"
]
}
Same for match
:
{
"match": {
"*.md": {
- "remove-useless-async": "off",
- "remove-useless-await": "off",
- "apply-top-level-await": "off"
+ "promises/remove-useless-async": "off",
+ "promises/remove-useless-await": "off",
+ "promises/apply-top-level-await": "off"
}
},
Otherwise if you didn't disable any of mentioned rules, that's awesome have a party ๐!
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
Published by coderaiser about 3 years ago
Published by coderaiser about 3 years ago