Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-prettier

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-prettier - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

57

index.js

@@ -5,3 +5,3 @@ 'use strict'

const path = require('path')
const glob = require('glob')
const globby = require('globby')
const ignores = require('ignore')()

@@ -42,25 +42,38 @@ const prettier = require('prettier')

function matchFiles() {
return new Promise((resolve, reject) => {
glob(options.files.join(), options.glob, (err, matches) => {
if (err) {
reject(err)
}
resolve(rules.filter(matches))
})
})
let changeFileCount = 0
function filterIgnores(paths) {
return Promise.resolve(rules.filter(paths))
}
matchFiles().then(filenames => {
filenames.forEach(filename => {
const filePath = path.resolve(filename)
const content = fs.readFileSync(filePath, 'utf-8')
const formatted = prettier.format(content, prettierConfig)
if (content !== formatted) {
fs.writeFileSync(filePath, formatted, 'utf-8')
log('write', filePath)
}
})
log('Finished')
})
function findGlobMatches(files) {
return globby(files, options.glob)
}
function writeFileIfNecessary(filename) {
const filePath = path.resolve(filename)
const content = fs.readFileSync(filePath, 'utf-8')
const formatted = prettier.format(content, prettierConfig)
if (content !== formatted) {
changeFileCount++
fs.writeFileSync(filePath, formatted, 'utf-8')
log('write', filePath)
}
}
function batchWriteFiles(files) {
files.forEach(writeFileIfNecessary)
if (changeFileCount === 0) {
log('No File Changed!')
} else {
log('Overwrite Finished')
}
}
function main() {
findGlobMatches(options.files).then(filterIgnores).then(batchWriteFiles)
}
// execute
main()
{
"name": "auto-prettier",
"version": "1.0.0",
"version": "1.1.0",
"description": "",

@@ -14,3 +14,3 @@ "main": "index.js",

"dependencies": {
"glob": "^7.1.2",
"globby": "^6.1.0",
"ignore": "^3.3.3",

@@ -17,0 +17,0 @@ "prettier": "^1.5.2"

# auto-prettier
> prettier with restricted rules
### Features
- Help you filter out ignorance in `.gitignore`
- Auto resolve your project directory
### Rules

@@ -27,5 +32,8 @@

"auto-prettier": {
"files": ["./src/**/*.js"]
"files": [
"src/**/*.js",
"test/**/*.js"
]
}
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc