Skip to content

Commit

Permalink
Add 'module-type' option determining how README is linted
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Apr 2, 2019
1 parent 77a4eb8 commit 5d5803a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Many variables have default values and are therefore optional.
| `opening-delimiter` | `` ```javascript `` | The opening delimiter of doctest blocks in the source files. |
| `closing-delimiter` | `` ``` `` | The closing delimiter of doctest blocks in the source files. |
| `version-tag-prefix` | `v` | The prefix of annotated version tags (`version-tag-prefix =` for no prefix). |
| `module-type` | `commonjs` | The type of module doctest should use. One of `commonjs`, `amd`, or `esm`. |

### Custom scripts

Expand All @@ -122,7 +123,7 @@ Runs [`doctest`↗︎][] with suitable `--module`, `--prefix`,
`--opening-delimiter`, and `--closing-delimiter` values.

Configurable via [variables][] (`source-files`, `comment-prefix`,
`opening-delimiter`, `closing-delimiter`).
`opening-delimiter`, `closing-delimiter`, `module-type`).

### `generate-readme`

Expand Down Expand Up @@ -190,7 +191,8 @@ undefined link references or unused link definitions.
Uses [`eslint`↗︎][] and [`eslint-plugin-markdown`↗︎][] to assert that the readme,
when built, will not contain examples which violate the project's style guide.

Configurable via [variables][] (`opening-delimiter`, `closing-delimiter`).
Configurable via [variables][] (`opening-delimiter`, `closing-delimiter`
`module-type`).

### `prepublish`

Expand Down
3 changes: 2 additions & 1 deletion bin/doctest
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ set +f ; shopt -s nullglob
files=($(get source-files))
set -f ; shopt -u nullglob

module="$(get module-type)"
prefix="$(get comment-prefix)"
opening="$(get opening-delimiter)"
closing="$(get closing-delimiter)"

node_modules/.bin/doctest \
--module commonjs \
--module "$module" \
--prefix "$prefix" \
--opening-delimiter "$opening" \
--closing-delimiter "$closing" \
Expand Down
9 changes: 8 additions & 1 deletion bin/lint-readme
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ node_modules/.bin/remark \
cp README.md README.md.temp
rewrite <README.md.temp >README.md

node_modules/.bin/eslint -- README.md
module="$(get module-type)"
if [[ $module == 'esm' ]] ; then
source = 'module'
else
source = 'script'
fi

node_modules/.bin/eslint --parser-options "sourceType:$source" -- README.md
1 change: 1 addition & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ get() {
closing-delimiter) # shellcheck disable=SC2016
printf '```' ;;
version-tag-prefix) printf 'v' ;;
module-type) printf 'commonjs' ;;
*)
echo "'$1' not defined in $config" >&2
return 1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"npm": ">=3.0.0"
},
"dependencies": {
"doctest": "0.16.x",
"doctest": "github:Avaq/doctest#avaq/esm",
"eslint": "5.15.x",
"eslint-plugin-markdown": "1.0.x",
"mocha": "5.x.x",
Expand Down

0 comments on commit 5d5803a

Please sign in to comment.