Skip to content

Instantly share code, notes, and snippets.

@watson
Last active July 13, 2023 22:42
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save watson/453fc63cace521fcdadc to your computer and use it in GitHub Desktop.
Save watson/453fc63cace521fcdadc 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/ *$//' {} \;
@hallas
Copy link

hallas commented Jul 25, 2015

Is this better than using standard-format, esformat, etc that is used by ogdens module?

@Whoaa512
Copy link

It is to be used in conjunction with them I believe.

@watson
Copy link
Author

watson commented Jul 25, 2015

@hallas @Whoaa512 haha... didn't know about about standard-format until now. Thanks @maxogden 😸

@hallas
Copy link

hallas commented Jul 25, 2015

@watson Oh okay 💃 Pretty nice stuff here none the less 🎯

@bcomnes
Copy link

bcomnes commented Aug 23, 2015

If you check the standard-format git history, you will find a similar set of regexs at the very beginning :)

@LinusU
Copy link

LinusU commented Aug 4, 2016

Standard 8 includes a --fix argument that is powered by eslint 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment