prettier-if-modified
v0.0.5
Published
Run `prettier` only on modified files.
Downloads
7
Maintainers
Readme
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