Skip to content

Commit

Permalink
Merge pull request #33 from SparkPost/SAA-466
Browse files Browse the repository at this point in the history
SAA-466 Updated all deps and prepped for v3 release.
  • Loading branch information
beardyman authored Jan 31, 2022
2 parents 5621ccc + f59c345 commit 0edc005
Show file tree
Hide file tree
Showing 10 changed files with 2,660 additions and 1,333 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @sparkpost/team-saz
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run eslint --fix
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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-27][3.0.0]
### Added
- Mocha specific config for linting testing files. This can be utilized by adding an `.eslintrc` file to your tests directory or adding an overrides
section and extending `sparkpost/mocha` within it.
- TypeScript specific config for linting TypeScript projects. Typescript projects can now extend `sparkpost/typescript`.

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

### Removed
- Removed TypeScript(TS) specific rules from the default config 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
112 changes: 50 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,77 @@
# eslint-config-sparkpost
ESLint configuration for Javascript based SparkPost projects



## 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`:
```json
{
"extends": "sparkpost/lib"
}
ESLint configuration for Javascript and TypeScript based SparkPost projects

## Upgrading from 2.x to 3.x
There were several breaking changes including moving from ESLint 5.x to ESLint 8.x. This change alone caused some minimal breaking changes. Since
we ultimately extend `eslint:recommended` in our base configuration, the upgrade from eslint 5.x to 8.x changed that 'recommended' config and the
rules between versions have definitely changed. We compensated to match our existing config as best we could, but you may find other changes when
running ESLint in your projects.

We also moved several specific configs from overrides in the base config to their own specific configs. Mocha and TypeScript are used by some projects,
however they are not used by every project so we have separated them to their own configs and moved their dependencies to optional peer dependencies
so that we no longer need to install and maintain them in projects that don't use them.

### Special Concerns for Mocha Based Projects
Traditionally we've setup special rules for `mocha` based projects, however not all projects use `mocha`. This would lead to dependencies being
installed that were unrelated to the project. For this reason, we have split `mocha` configuration into its own configuration. You can take
advantage of it by extending `sparkpost/mocha` from this package. This will require you to install the plugin `eslint-plugin-mocha` in the project's
dev dependencies.

Example:
```shell
npm i -D eslint-plugin-mocha
```


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

### Useful NPM scripts
In your `.eslintrc` file:
```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 "
}
"normal": "stuff <- comment",
"overrides": [
{
"files": ["test/**/*.spec.js"],
"extends": ["sparkpost/mocha"]
}
]
}
```

### Generating Docs
#### Install `doxdox`
```bash
npm i --save-dev doxdox
```
### Special Concerns for TypeScript Projects
We have several `typescript` based projects, however not all projects use `typescript`. This would lead to dependencies being
installed that were unrelated to the project. For this reason, we have split `typescript` configuration into its own configuration. You can take
advantage of it by extending `sparkpost/typescript` from this package. This will require you to install several plugins and configs in the project's
dev dependencies.

#### 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"
}
Example:
```shell
npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-prettier
```

#### 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.
In your `.eslintrc` file:
```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 "
"normal": "stuff <- comment",
"extends": ["sparkpost/typescript"],
"rules": {
"other": "rules that override the base typescript config <- comment"
}
}
```

#### Generating nicer docs
I recommend adding docs to your gitignore if its not already there.
```bash
echo docs >> .gitignore
```
## 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.

Add the npm script:
To use, add the following to your `.eslintrc` file:
```json
{
"nice-docs": "doxdox 'index.js' 'mocks/**/*.js' 'lib/**/*.js' --layout bootstrap --output docs/index.html && open docs/index.html"
"extends": "sparkpost/lib"
}
```

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

### Checking Changelogs
### Automation for Checking Changelogs
#### Add the npm scripts
```json
{
"chk-changelog": "grep `node -e 'console.log(require(\"./package.json\").version);'` CHANGELOG.md || echo 'Please update CHANGELOG.md with your updates'; exit 255",
"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.
3 changes: 1 addition & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module.exports = {
env: {
node: true,
mocha: true
node: true
},
extends: 'sparkpost/index'
};
55 changes: 2 additions & 53 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ module.exports = {
es6: true
},
parserOptions: {
ecmaVersion: 2018
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,51 +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/@typescript-eslint',
'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'
}
]
}
}
]
}
};
25 changes: 25 additions & 0 deletions mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


module.exports = {
env: {
es6: true,
node: true,
mocha: 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 0edc005

Please sign in to comment.