Skip to content

Instantly share code, notes, and snippets.

@derekedelaney
Last active May 16, 2018 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekedelaney/45f4d6d7fcf9a527a049ecb88f6a52c2 to your computer and use it in GitHub Desktop.
Save derekedelaney/45f4d6d7fcf9a527a049ecb88f6a52c2 to your computer and use it in GitHub Desktop.
Prints the directory if there is a missing spec file for javascript. Use `--exclusions` to ignore keywords in a file name.
import os
import sys
import argparse
def no_spec_file(rootdir, exclusions):
for subdir, dirs, files in os.walk(rootdir):
for file in files:
split_file = os.path.join(subdir, file).split('.')
if len(split_file) == 2 and split_file[1] == 'js':
spec_file = split_file[0]+'.spec.js'
if not os.path.isfile(spec_file) and not any(word in file for word in exclusions):
print os.path.join(subdir, file)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("root_dir", help="Name of the root directory")
parser.add_argument("--exclusions", help="A list of words to exclude from the file name", nargs="*", default=[])
args = parser.parse_args()
if not no_spec_file(args.root_dir, args.exclusions):
sys.exit(1)
if __name__ == "__main__":
main()
@derekedelaney
Copy link
Author

Run using python /path/to/no_spec_file.py /path/to/src/folder/to/check

@derekedelaney
Copy link
Author

Ignore keywords with --exclusions
python /path/to/no_spec_file.py /path/to/src/folder/to/check --exclusions settings constants Constants

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