JavaScript linter based on FAT image
npm install fatlint[NPMURL]: https://npmjs.org/package/fatlint "npm"
[NPMIMGURL]: https://img.shields.io/npm/v/fatlint.svg?style=flat
[BuildStatusURL]: https://github.com/coderaiser/fatlint/actions?query=workflow%3A%22Node+CI%22 "Build Status"
[BuildStatusIMGURL]: https://github.com/coderaiser/fatlint/workflows/Node%20CI/badge.svg
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[CoverageURL]: https://coveralls.io/github/coderaiser/fatlint?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/fatlint/badge.svg?branch=master&service=github
FAT-based JavaScript linter. The main idea is using FAT-filesystem for traversing AST,
so each node written to a file.
```
npm i fatlint
traverse willing to support similar API as @babel/traverse.
`js
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;`
`js
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;`
`js
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;`
`js
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;`
`js
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;`
Get next sibling.
`js
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;`
Get prev sibling.
`js
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;`
`js
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;`
`js
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;`
`js
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;
``
MIT