AST querying for lazy people.
import { js, pipe, select, all } from 'affe'
const config = await readFile('eslint.config.js', 'utf8')
const rules = await pipe(
js(config),
select(`
export property[name=rules]
> value > object > property > key > *
`),
all(),
)
console.log(rules)
Contents
Installation
Node:
npm i affe
Browser / Deno:
import { js } from 'https://esm.sh/affe'
Usage
affe
simplifies ANY syntax tree into a format that can be queried with a CSS-like syntax. It also provides tooling for
further simplification of ASTs of a specific language
for more convenience.
affe
provides support for JavaScript/JSX out of the box, but you can easily add support for any other language.
import { jsx, pipe, select, pick, all } from 'affe'
const code = jsx`
export default ({ name, style }) => (
<div className={style}>Hello, {name}!</div>
)
`
const params = pipe(
code,
select('export params property key *'),
pick(node => node.name ?? node.value),
all(),
)
console.log(params)
Contribution
You need node, NPM to start and git to start.
git clone git@github.com:loreanvictor/affe.git
npm i
Make sure all checks are successful on your PRs. This includes all tests passing, high code coverage, correct typings and abiding all the linting rules. The code is typed with TypeScript, Jest is used for testing and coverage reports, ESLint and TypeScript ESLint are used for linting. Subsequently, IDE integrations for TypeScript and ESLint would make your life much easier (for example, VSCode supports TypeScript out of the box and has this nice ESLint plugin), but you could also use the following commands:
npm test
npm run coverage
npm run lint
npm run typecheck