Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Added use strict helper script to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdeandrade committed Nov 25, 2014
1 parent 952d0b7 commit e422e06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/eslint/global-strict.md
Expand Up @@ -13,6 +13,32 @@ and should not be an error.
Strict mode also causes modifications to objects frozen with
`Object.freeze` to throw TypeErrors, which is desirable.

If you need a quick and easy way to add `'use strict'` to
every JavaScript file in your project, you can use the
execute the following shell script at the root of your
project:

git ls-files | grep \.js$ |
while read f; do
if (head -n3 "$f" | grep -Fv 'use strict' > /dev/null); then
echo "$f"
if (head -n1 "$f" | grep -Fv '#!/' > /dev/null); then
sed -i '' -e '1 i\
'\''use strict'\'';
' "$f"
else
sed -i '' -e '2 i\
'\''use strict'\'';
' "$f"
fi
fi
done

Just save that in a file, `chmod +x` it, and then execute
it. I recommend you double check that everything worked
correctly with `git diff` before you lint again and commit
your changes.

[Official `global-strict` ESLint Rule Documentation][global-strict-docs]

[global-strict-docs]: https://github.com/eslint/eslint/blob/master/docs/rules/global-strict.md

0 comments on commit e422e06

Please sign in to comment.