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.
Non-incremental:
prettier --write "**/*.js"
Incremental:
prettier-if-modified "**/*.js" -- prettier --write
With .prettierignore
:
prettier-if-modified --ignore-path .prettierignore "**/*.js" -- prettier --write
// 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)
})
# Install dependencies
yarn install
# Format source code
yarn format
MIT © Mark Tiedemann