Skip to content

The library allows to modify the AST before executing Prettier.

Notifications You must be signed in to change notification settings

suguru03/prettier-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prettier Hook

The library allows to modify the AST before executing Prettier.

const { hooks } = require('prettier-hook');

function parse(ast) {
  // modify AST
  return ast;
}

hooks.typescript.addHook(parse);
npx prettier-hook --require <filepath>
// or
yarn prettier-hook --require <filepath>

Example

There is an example which is converting require to import.

// examples/simple/test.js
const fs = require('fs');
$ DEBUG=1 yarn ts-node dist/bin/prettier-hook.js --require examples/simple/index.ts examples/simple/test.js
// examples/simple/test.js
import * as fs from 'fs';

Use case

About

The library allows to modify the AST before executing Prettier.

Resources

Stars

Watchers

Forks

Packages

No packages published