2.0.12 • Published 1 year ago
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 fatlintAPI
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
1.14.1
1 year ago
1.14.0
1 year ago
1.12.0
1 year ago
1.18.1
1 year ago
1.18.0
1 year ago
1.16.1
1 year ago
1.16.0
1 year ago
1.18.3
1 year ago
1.18.2
1 year ago
2.0.3
1 year ago
2.0.2
1 year ago
2.0.5
1 year ago
2.0.4
1 year ago
2.0.7
1 year ago
2.0.6
1 year ago
2.0.9
1 year ago
2.0.8
1 year ago
2.0.1
1 year ago
2.0.0
1 year ago
1.15.0
1 year ago
1.13.1
1 year ago
1.13.0
1 year ago
1.17.0
1 year ago
2.0.11
1 year ago
2.0.12
1 year ago
2.0.10
1 year ago
1.2.0
1 year ago
1.1.0
1 year ago
1.9.1
1 year ago
1.9.0
1 year ago
1.8.1
1 year ago
1.7.2
1 year ago
1.8.0
1 year ago
1.7.1
1 year ago
1.4.4
1 year ago
1.7.0
1 year ago
1.6.1
1 year ago
1.4.3
1 year ago
1.6.0
1 year ago
1.4.2
1 year ago
1.5.0
1 year ago
1.4.1
1 year ago
1.4.0
1 year ago
1.3.0
1 year ago
1.2.1
1 year ago
1.11.0
1 year ago
1.10.0
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.0
1 year ago