fatlint v2.0.12
FatLint

FAT-based JavaScript linter. The main idea is using FAT-filesystem for traversing AST, so each node written to a file.
Install
npm i fatlint
API
traverse
willing to support similar API as @babel/traverse
.
remove()
import {
traverse,
parse,
print,
} from 'fatlint';
import {types} from 'putout';
const {isIdentifier} = types;
const source = `const a = 'hello'; const b = 'world'`;
const filesystem = parse(source, disk);
traverse(filesystem, {
VariableDeclarator(path) {
if (isIdentifier(path.node.id, {name: 'world'}))
path.remove(path);
},
});
print(filesystem);
// returns
`const a = 'hello'\n`;
replaceWith()
import {types} from 'putout';
import {
traverse,
parse,
print,
} from 'fatlint';
const {numericLiteral} = types;
const source = `const a = 'hello';`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path.replaceWith(numericLiteral(5));
},
});
print(filesystem);
// returns
`const a = 5;\n`;
replaceWithMultiple()
import {types} from 'putout';
import {
traverse,
parse,
print,
} from 'fatlint';
const {numericLiteral} = types;
const source = `const a = ['hello']`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path.replaceWithMultipleNodes([
numericLiteral(5),
numericLiteral(3),
]);
},
});
print(filesystem);
// returns
`const a = [5, 3];\n`;
insertBefore()
import {types} from 'putout';
import {
traverse,
parse,
print,
} from 'fatlint';
const {numericLiteral} = types;
const source = `const a = ['hello']`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path.insertBefore(numericLiteral(5));
},
});
print(filesystem);
// returns
`const a = [5, 'hello'];\n`;
insertAfter()
import {types} from 'putout';
import {
traverse,
parse,
print,
} from 'fatlint';
const {numericLiteral} = types;
const source = `const a = ['hello']`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path.insertAfter(numericLiteral(5));
},
});
print(filesystem);
// returns
`const a = ['hello', 5];\n`;
getNextSibling()
Get next sibling.
import {types} from 'putout';
import {
traverse,
parse,
print,
createDisk,
} from 'fatlint';
const disk = await createDisk();
const source = `const a = 'hello'; const b = 'world'`;
const filesystem = parse(source, disk);
traverse(filesystem, {
VariableDeclaration(path) {
path
.getNextSibling()
.remove();
},
});
print(filesystem);
// returns
`const a = 'hello';\n`;
getPrevSibling()
Get prev sibling.
import {types} from 'putout';
import {
traverse,
parse,
print,
createDisk,
} from 'fatlint';
const disk = await createDisk();
const source = `const a = 'hello'; const b = 'world'`;
const filesystem = parse(source, disk);
traverse(filesystem, {
VariableDeclaration(path) {
path
.getPrevSibling()
.remove();
},
});
print(filesystem);
// returns
`const b = 'world';\n`;
path.find()
import {types} from 'putout';
import {
traverse,
parse,
print,
createDisk,
} from 'fatlint';
const {isVariableDeclaration} = types;
const disk = await createDisk();
const source = `function x() {const a = 'hello'; const b = 'world';}`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path
.find(isVariableDeclaration)
.remove();
},
});
print(filesystem);
// returns
`function x() {}\n`;
path.parentPath
import {types} from 'putout';
import {
traverse,
parse,
print,
createDisk,
} from 'fatlint';
const {isVariableDeclaration} = types;
const disk = await createDisk();
const source = `function x() {const a = 'hello'; const b = 'world';}`;
const filesystem = parse(source, disk);
traverse(filesystem, {
StringLiteral(path) {
path.parentPath.remove();
},
});
print(filesystem);
// returns
`function x() {}\n`;
path.stop()
path.parentPath
import {types} from 'putout';
import {
traverse,
parse,
print,
createDisk,
} from 'fatlint';
const {isVariableDeclaration} = types;
const disk = await createDisk();
const source = `function x() {const a = 'hello'; const b = 'world';}`;
const filesystem = parse(source, disk);
let counter = 0;
traverse(filesystem, {
StringLiteral(path) {
++counter;
path.parentPath.stop();
},
});
console.log(counter);
// outputs
1;
License
MIT
3 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago