Skip to content

MarkTiedemann/prettier-if-modified

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prettier-if-modified

Run prettier only on modified files.

This module uses file attributes to keep track of when files have been modified and formatted. Only files that were modified after they have been formatted will be passed on to prettier to be formatted again. As such, this module enables incremental formatting for codebases of all sizes.

Usage

Non-incremental:

prettier --write "**/*.js"

Incremental:

prettier-if-modified "**/*.js" -- prettier --write

With .prettierignore:

prettier-if-modified --ignore-path .prettierignore "**/*.js" -- prettier --write

Algorithm

// WARNING: THIS IS SIMPLIFIED PSEUDOCODE

let all_files = find_files('**/*.js')

let modified_files = all_files.filter(file => {
  let last_modified = get_attribute(file, 'last_modified')
  let last_formatted = get_attribute(file, 'last_formatted')
  return last_modified > last_formatted
})

prettier(modified_files)

let last_formatted = Date.now()
modified_files.forEach(file => {
  set_attribute(file, 'last_formatted', last_formatted)
})

Development

# Install dependencies
yarn install

# Format source code
yarn format

License

MIT © Mark Tiedemann

About

Run `prettier` only on modified files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published