Skip to content

Instantly share code, notes, and snippets.

@charrismatic
Forked from watson/README.md
Last active October 18, 2018 06:07
Show Gist options
  • Save charrismatic/5bad729f49ee600a0cef08771cd7800a to your computer and use it in GitHub Desktop.
Save charrismatic/5bad729f49ee600a0cef08771cd7800a to your computer and use it in GitHub Desktop.
A list of search and replace unix commands to help make a node repository 'standard' compliant

The standard code style linter is a great tool by Feross - check it out!

Remove trailing semicolons:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/;$//' {} \;

Ensure space between function and opening bracket:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/function(/function (/g' {} \;

Ensure space after colons in object literal:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -E -e 's/:([^ ])/: \1/g' {} \;

Ensure space after commas in object literal:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -E -e 's/,([^ ])/, \1/g' {} \;

Use single quotes when defining strings:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -E -e "s/\"/'/g" {} \;

Note that this is by no means foolproof as it will also convert the double quotes inside the string 'foo"bar'!

Remove space in front of commas:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/ *,/,/g' {} \;

Ensure one a single space around equal signs:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/  *=  */ = /g' {} \;

Remove space in front of colons:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/ *:/:/g' {} \;

Remove trailing line space:

find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e 's/ *$//' {} \;
#!bin/bash
# =============================================================================
# QUICK ATTEMPT TO FUNCTIONALIZE THE FIXERS DEFINED BY THE SOURCE DOCUMENT
# =============================================================================
# Example: You should be able to use each functions by piping data through them
#
# ```
# node-sass $INPUT --output-style expanded | line_ending_spaces \
# | kill_trailing_colons | tee save/this/file.html \
# | postcss -u cssnano > save.this.minified.hmtml
# ```
#
# Remove trailing semicolons
# -----------------------------------------------------------------------------
kill_trailing_colons () {
sed -e 's/;$//'
}
# Ensure space between `function` and opening bracket
# -----------------------------------------------------------------------------
function_open_braces_spaces () {
sed -e 's/function(/function (/g'
}
# Ensure space after colons in object literal
# -----------------------------------------------------------------------------
object_colon_spaces () {
sed -E -e 's/:([^ ])/: \1/g'
}
# Ensure space after commas in object literal
# -----------------------------------------------------------------------------
object_comma_spaces () {
sed -E -e 's/,([^ ])/, \1/g'
}
# Use single quotes when defining strings
# -----------------------------------------------------------------------------
single_quoted_strings () {
sed -E -e "s/\"/'/g"
}
# Remove space in front of commas
# -----------------------------------------------------------------------------
# Note: that this is by no means foolproof as it will also convert the double
# quotes inside the string `'foo"bar'`!
no_comma_spaces_left () {
sed -e 's/ *,/,/g'
}
# Ensure one a single space around equal signs
# -----------------------------------------------------------------------------
equals_spaces () {
sed -e 's/ *= */ = /g'
}
# Remove space in front of colons
# -----------------------------------------------------------------------------
no_colon_spaces_left () {
sed -e 's/ *:/:/g'
}
# Remove trailing line space
# -----------------------------------------------------------------------------
lines_no_trailing_spaces () {
sed -e 's/ *$//'
}
# EXAMPLE: Main - `FMT_RULES` is some selected combination of above fixers
# -----------------------------------------------------------------------------
fixe_project_format () {
find . -path ./node_modules -prune -o -type f -name '*.js' -exec sed -i '' -e $FMT_RULES {} \;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment