Skip to content

Commit

Permalink
SAA-466 moved mocha plugin stuff to be optional peer dependencies and…
Browse files Browse the repository at this point in the history
… created a new sparkpost/mocha config to be utilized in tests.
  • Loading branch information
beardyman committed Jan 26, 2022
1 parent 4cad8cc commit b13eb13
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1,076 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
- There are no unreleased features at this time

## [3.0.0 - 2022-01-26][3.0.0]
### Added
- Mocha specific config for linting testing. This can be utilized by adding an `.eslintrc` file to your tests directory and extending `sparkpost/mocha` within it.

### Updated
- Updated the required version of ESLint to be 8.7 or above

### Removed
- Removed TypeScript(TS) specific rules since they add TS dependencies to non-TS projects.
This will be followed by a TS specific linting config for TS projects that will potentially inherit base JS settings from this configuration.
- Moved Mocha specific plugins to be optional peer dependencies. This allows non-Mocha based projects to not install the Mocha plugins if they're not
needed. This has been replaced with a mocha specific config `sparkpost/mocha` which can be added to an `.eslintrc` file in the tests directory of
Mocha based projects.

[3.0.0]: https://github.com/sparkpost/eslint-config-sparkpost/compare/v2.1.2...v3.0.0
67 changes: 3 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,21 @@
# eslint-config-sparkpost
ESLint configuration for Javascript based SparkPost projects

## Updating from Version 2 to Version 3


## Notes for Docs in Libraries

This config has extra rules specifically around JSDocs to help have better documentation in our libraries.
This can help in knowledge sharing and will hopefully promote better docs in our shared JS modules.

To use, add the following to your `.eslintrc.json`:
To use, add the following to your `.eslintrc` file:
```json
{
"extends": "sparkpost/lib"
}
```


The scripts below in this README are purely for reference and can make managing documentation in your shared lib much easier.

### Useful NPM scripts
```json
{
"scripts": {
"chk-changelog": "grep `node -e 'console.log(require(\"./package.json\").version);'` CHANGELOG.md || echo 'Please update CHANGELOG.md with your updates'; exit 255",
"docs": "doxdox index.js 'mocks/**/*.js' 'lib/**/*.js' --layout markdown --output DOCUMENTATION.md",
"lint": "eslint . --fix",
"nice-docs": "doxdox 'index.js' 'mocks/**/*.js' 'lib/**/*.js' --layout bootstrap --output docs/index.html && open docs/index.html",
"prepublishOnly": "npm run chk-changelog",
"prepush": "npm run docs -- && git add DOCUMENTATION.md && if git commit --no-verify -m \"`git rev-parse --abbrev-ref HEAD` Updated Documentation\"; then exit 0; else echo 'No documentation updates'; fi "
}
}
```

### Generating Docs
#### Install `doxdox`
```bash
npm i --save-dev doxdox
```

#### Add and modify the npm script.
The list below (`index.js 'mocks/**/*.js 'lib/**/*.js`) will probably need to be changed for your lib.
```json
{
"docs": "doxdox index.js 'mocks/**/*.js' 'lib/**/*.js' --layout markdown --output DOCUMENTATION.md"
}
```

#### Run the script
```bash
npm run docs
```
This will generate a ./DOCUMENTATION.md file that will include all JSDoc references in your module.

#### Auto generating the docs
Given that you have husky installed, adding an npm script for `prepush` will automatically generate and commit docs anytime you push to git.
```json
{
"prepush": "npm run docs -- && git add DOCUMENTATION.md && if git commit --no-verify -m \"`git rev-parse --abbrev-ref HEAD` Updated Documentation\"; then exit 0; else echo 'No documentation updates'; fi "
}
```

#### Generating nicer docs
I recommend adding docs to your gitignore if its not already there.
```bash
echo docs >> .gitignore
```

Add the npm script:
```json
{
"nice-docs": "doxdox 'index.js' 'mocks/**/*.js' 'lib/**/*.js' --layout bootstrap --output docs/index.html && open docs/index.html"
}
```

Run the npm script
```bash
npm run nice-docs
```

### Checking Changelogs
#### Add the npm scripts
Expand All @@ -86,4 +25,4 @@ npm run nice-docs
"prepublishOnly": "npm run chk-changelog"
}
```
This will check your changelog for an entry for your current version when you publish.
This will check your changelog for an entry for your current version when you publish.
52 changes: 1 addition & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
parserOptions: {
ecmaVersion: 2021
},
plugins: ['mocha'],
extends: ['eslint:recommended'],
rules: {
'arrow-body-style': ['error', 'as-needed'],
Expand All @@ -30,10 +29,6 @@ module.exports = {
'keyword-spacing': ['error', { before: true, after: true }],
'linebreak-style': ['error', 'unix'],
'max-params': ['error', 3],
'mocha/no-exclusive-tests': 'error',
'mocha/no-mocha-arrows': 'error',
'mocha/no-identical-title': 'error',
'mocha/no-sibling-hooks': 'error',
'new-cap': 'error',
'no-caller': 'error',
quotes: ['error', 'single'],
Expand Down Expand Up @@ -76,50 +71,5 @@ module.exports = {
'vars-on-top': 'error',
'wrap-iife': ['error', 'any'],
yoda: ['error', 'never']
},
overrides: [
{
files: ['*.spec.js'],
rules: {
'max-params': 'off',
'func-names': 'off',
'prefer-arrow-callback': 'off'
}
},
{
files: ['*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended'
],
env: {
es6: true
},
parser: '@typescript-eslint/parser',
plugins: ['prettier', 'mocha', '@typescript-eslint'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{
functions: false,
classes: false,
variables: true
}
],
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none'
}
]
}
}
]
}
};
23 changes: 23 additions & 0 deletions mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


module.exports = {
env: {
es6: true
},
parserOptions: {
ecmaVersion: 2021
},
plugins: ['mocha'],
extends: ['sparkpost/index'],
rules: {
'max-params': 'off',
'func-names': 'off',
'prefer-arrow-callback': 'off',
'require-jsdoc': 'off',
'valid-jsdoc': 'off',
'mocha/no-exclusive-tests': 'error',
'mocha/no-mocha-arrows': 'error',
'mocha/no-identical-title': 'error',
'mocha/no-sibling-hooks': 'error'
}
}
Loading

0 comments on commit b13eb13

Please sign in to comment.