π 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 almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
ESM
-friendlyβWisdom tells me I am nothing. Love tells me I am everything. And between the two my life flows.β
β Nisargadatta Maharaj
Giorgio Liberale da Udine, Crocodile (16th c.)
Hi friends π ! EcmaScript Modules
gets more and more popular, and πPutout
goes towards community needs, and added some sweets in todays release π¬ .
ESM
FormattersThat's right! Formatters now can be in one of two formats CommonJS
:
module.exports = function formatter({name, source, places, index, count, filesCount, errorsCount}) {
return '';
}
or ESM
:
export default function formatter({name, source, places, index, count, filesCount, errorsCount}) {
return '';
}
Both supported π₯³ !
And they can be async
functions as well π:
export default async function formatter({name, source, places, index, count, filesCount, errorsCount}) {
return '';
}
Since ESLint v8.4.0
has support of async functions and πPutout
has @putout/formatter-eslint which supports all ESLint
formatters this way:
ESLINT_FORMATTER=pretty putout --format eslint lib
It will work as well with promises starting from this release π .
async
tests for formattersSince formatters can be ESM
and async
, tests for them should support this change. And with @putout/test v4.0.0
, it looks this way:
test('formatter: codeframe', async ({format}) => {
await format(codeframe);
});
That's awesome π ! You definitely can, and it's highly appreciated π! You can find all the information in Convert formatters to ESM issue.
Also good first issue will always help you to find beginners-friendly issues, so you can helps a lot to project in a simplest possible way π .
Have a nice day and happy coding β¨οΈ !
Published by coderaiser almost 3 years ago
PUTOUT_CONFIG_FILE
Just landed πPutout
v22.4.0 with ability to override default config with help of PUTOUT_CONFIG_FILE
env variable (in the similar way as it works with ESLINT_CONFIG_FILE
):
PUTOUT_CONFIG_FILE=.putout-off.json putout . --no-config
With .putout-off.json
:
{
"formatter": "progress-bar",
"rules": {
"remove-unused-variables": "on"
},
"processors": [
"javascript",
"json",
"markdown",
"ignore",
"yaml",
"css"
],
"ignore": [
"**/node_modules",
],
"plugins": [
"remove-unused-variables"
]
}
It runs one rule remove-unused-variables
. So you can add any rules you want :).
TypeScript
in ESLint
plugineslint-plugin-putout
v12.0.0
has better support of TypeScript
because it uses @typescript-eslint
and a lot of it's rules to format TypeScript
files π .
PUTOUT_CONFIG_FILE
eslint-plugin-putout
) ts: add extension ruleseslint-plugin-putout
) ts: enable @typescript-eslint/type-annotation-spacingeslint-plugin-putout
) safe: add remove-useless-argumentseslint-plugin-putout
) tape-remove-newline-before-t-end: add support of case when no assertions found before t.end()eslint-plugin-putout
) ts: disable: ban-types, no-explicit-any, no-empty-functioneslint-plugin-putout
) drop support of putout < 22eslint-plugin-putout
) add first class support of typescripteslint-plugin-putout
) improve support of add-newline-{before,after}-function-call@putout/plugin-remove-empty-pattern
) add support of nested ArrayPattern
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Just added config
validation, so if your .putout.json
has something like this:
{
"hello": "world"
}
You will see error message:
π .putout.json: hello: must NOT have additional properties
And πPutout
exits with exit code 12
(INVALID_CONFIG
).
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
typescript-eslint
If night and day were to approach the Sun, Both would disappear.
In the same way, their duality would vanish
If their essential unity were seen(c) Jnaneshvara "Amritanubhav"
TypeScript
nodes supported πͺThanks for an issue reported by @brunoparga , typescrit-eslint
support improved drastically π .
It's AST
has couple differences with @babel/parser
that should be handled.
To the point! When you use .eslintrc.json
:
{
"parser": "@typescript-eslint/parser",
"plugins": [
"putout",
"@typescript-eslint"
],
"extends": [
"plugin:putout/recommended",
"plugin:@typescript-eslint/recommended"
]
}
With help of estree-to-babel, such constructs:
// TSClassImplements
class A implements B {
}
// TSInterfaceHeritage
interface x extends y.z.m {
}
// TSAbstractMethodDefinition
class Base {
abstract getName(): string;
}
// PrivateIdentifier
class ClassWithPrivateField implements B{
#privateField;
pubplicField = 5;
constructor() {
this.#privateField = 5;
}
}
Will work as expected, and will be parsed without a problem.
here is a circle of transformations: TypeScript AST -> ESTree -> Babel
. But that's not a problem for estree-to-babel
.
When using both typescript-eslint
and eslint-plugin-putout
there was an issue with comments
:
/**
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { ICircularList } from 'common/Types';
/**
* Represents a circular list; a list with a maximum size that wraps around when push is called,
* overriding values at the start of the list.
*/
export class CircularList<T> implements ICircularList<T> {
get maxLength() {
if (2) // <-- should be removed with remove-constant-conditions
alert();
return this._maxLength;
}
}
After applying fixes all comments
go on top:
/**
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
* @license MIT
*/
/**
* Represents a circular list; a list with a maximum size that wraps around when push is called,
* overriding values at the start of the list.
*/
import { ICircularList } from 'common/Types';
export class CircularList<T> implements ICircularList<T> {
get maxLength() {
alert();
return this._maxLength;
}
}
Which is very bad and has no sense. Starting from eslint-plugin-putout v11.18.0
it's fixed, and comments
placed in the way they should:
/**
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { ICircularList } from 'common/Types';
/**
* Represents a circular list; a list with a maximum size that wraps around when push is called,
* overriding values at the start of the list.
*/
export class CircularList<T> implements ICircularList<T> {
get maxLength() {
alert();
return this._maxLength;
}
}
That's all folks π.
Have a nice day!
If you got any problems, create an issue!
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Published by coderaiser almost 3 years ago
Preoccupied with a single leaf, you won't see the tree.
Preoccupied with a single tree, you'll miss the entire forest.(c) Takuan Soho
@putout/plugin-apply-filter-boolean
is removed from default installation, since @putout/plugin-remove-useless-functions does all the same thing and much more π !
If you had apply-filter-boolean
disabled, all you have to do is:
{
"rules": {
- "apply-filter-boolean": "off"
}
}
Published by coderaiser almost 3 years ago
apply-filter-boolean
π₯@putout/plugin-apply-filter-boolean
is disabled and will be removed from default installation on next major bump of Putout
. Thanks to @B2o5T for helping me to understand that @putout/plugin-remove-useless-functions feats much more for this purpose in https://github.com/coderaiser/putout/pull/86 π
So now all kinds of code:
[].filter((a) => a);
[].find((a) => a);
[].findIndex((a) => a);
[].some((a) => a);
[].every((a) => a);
Will be fixed to:
[].filter(Boolean);
[].find(Boolean);
[].findIndex(Boolean);
[].some(Boolean);
[].every(Boolean);
Published by coderaiser almost 3 years ago