diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f9fde81de..406d5bb87 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,13 +12,13 @@ Adding New Lints ---------------- **Generating Lint Scaffolding.** The scaffolding for a new lints can be created -by running `./newLint.sh `. Path name may be +by running `./newLint.sh -r -n -s `. Path name may be one of the existing folders under `lints` (for example `apple`, `cabf_br`, `rfc` etc) and the choice depends on who authors/suggests the lint specification. Lint names are generally of the form `e_subject_common_name_not_from_san` where the first letter is one of: `e`, `w`, or `n` (error, warning, or notice respectively). Struct names following Go conventions, e.g., `subjectCommonNameNotFromSAN`. Example: -`./newLint.sh rfc e_subject_common_name_not_from_san subjectCommonNameNotFromSAN`. +`./newLint.sh -r rfc -n e_subject_common_name_not_from_san -s subjectCommonNameNotFromSAN`. This will generate a new lint in the `lints/rfc` directory with the necessary fields filled out. diff --git a/v3/newLint.sh b/v3/newLint.sh index 859d8e93f..bf19af24a 100755 --- a/v3/newLint.sh +++ b/v3/newLint.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash function usage() { - echo "./newLint.sh [-h|--help] -r|--req -f|--file -s|--struct " + echo "./newLint.sh [-h|--help] -r|--req -n|--name -s|--struct " echo "" echo "Options:" echo " -h|--help Prints this help text." echo " -r|--req The name of the requirements body governing this lint. Valid options are $(valid_requirement_names)." - echo " -f|--file The target filename for the given lint (no file extension is required)." + echo " -n|--name The lintname for the given lints." echo " -s|--struct The name of the Golang struct to create." echo "" echo "Example:" @@ -45,10 +45,8 @@ while [[ $# -gt 0 ]]; do REQUIREMENT="${2}" shift 2 ;; - -f | --file) + -n| --name) LINTNAME="${2}" - FILENAME="lint_${LINTNAME}.go" - TEST_FILENAME="lint_${LINTNAME}_test.go" shift 2 ;; -s | --struct) @@ -67,6 +65,15 @@ while [[ $# -gt 0 ]]; do esac done +if [[ $LINTNAME =~ ^[enw]_ ]]; then + FILENAME="lint_${LINTNAME:2}.go" + TEST_FILENAME="lint_${LINTNAME:2}_test.go" +else + echo "The lintname should start with e_, w_, n_" + usage + exit 1 +fi + if [ -z "${REQUIREMENT}" ]; then echo "The -r|--req flag is required. Valid options are $(valid_requirement_names)" usage @@ -74,27 +81,30 @@ if [ -z "${REQUIREMENT}" ]; then fi if [ -z "${LINTNAME}" ]; then - echo "The -f|--file flag is required." + echo "The -n|--name flag is required." usage exit 1 fi if [ -z "${STRUCTNAME}" ]; then - echo "The -s|--strut flag is required." + echo "The -s|--struct flag is required." usage exit 1 fi +echo $STRUCTNAME PATHNAME="$(git_root)/v3/lints/${REQUIREMENT}/${FILENAME}" TEST_PATHNAME="$(git_root)/v3/lints/${REQUIREMENT}/${TEST_FILENAME}" +echo "$(git_root)/v3/template" +echo "$(git_root)/v3/test_template" sed -e "s/PACKAGE/${REQUIREMENT}/" \ - -e "s/PASCAL_CASE_SUBST/${STRUCTNAME^}/g" \ + -e "s/PASCAL_CASE_SUBST/${STRUCTNAME}/g" \ -e "s/SUBST/${STRUCTNAME}/g" \ -e "s/SUBTEST/${LINTNAME}/g" "$(git_root)/v3/template" > "${PATHNAME}" sed -e "s/PACKAGE/${REQUIREMENT}/" \ - -e "s/PASCAL_CASE_SUBST/${STRUCTNAME^}/g" \ + -e "s/PASCAL_CASE_SUBST/${STRUCTNAME}/g" \ -e "s/SUBST/${STRUCTNAME}/g" \ -e "s/SUBTEST/${LINTNAME}/g" "$(git_root)/v3/test_template" > "${TEST_PATHNAME}"