Skip to content

Commit 0edc005

Browse files
authored
Merge pull request #33 from SparkPost/SAA-466
SAA-466 Updated all deps and prepped for v3 release.
2 parents 5621ccc + f59c345 commit 0edc005

File tree

10 files changed

+2660
-1333
lines changed

10 files changed

+2660
-1333
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @sparkpost/team-saz

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run eslint --fix

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## [Unreleased][unreleased]
6+
- There are no unreleased features at this time
7+
8+
## [3.0.0 - 2022-01-27][3.0.0]
9+
### Added
10+
- Mocha specific config for linting testing files. This can be utilized by adding an `.eslintrc` file to your tests directory or adding an overrides
11+
section and extending `sparkpost/mocha` within it.
12+
- TypeScript specific config for linting TypeScript projects. Typescript projects can now extend `sparkpost/typescript`.
13+
14+
### Updated
15+
- Updated the required version of ESLint to be 8.7 or above
16+
17+
### Removed
18+
- Removed TypeScript(TS) specific rules from the default config since they add TS dependencies to non-TS projects.
19+
This will be followed by a TS specific linting config for TS projects that will potentially inherit base JS settings from this configuration.
20+
- 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
21+
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
22+
Mocha based projects.
23+
24+
[3.0.0]: https://github.com/sparkpost/eslint-config-sparkpost/compare/v2.1.2...v3.0.0

README.md

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,77 @@
11
# eslint-config-sparkpost
2-
ESLint configuration for Javascript based SparkPost projects
3-
4-
5-
6-
## Notes for Docs in Libraries
7-
8-
This config has extra rules specifically around JSDocs to help have better documentation in our libraries.
9-
This can help in knowledge sharing and will hopefully promote better docs in our shared JS modules.
10-
11-
To use, add the following to your `.eslintrc.json`:
12-
```json
13-
{
14-
"extends": "sparkpost/lib"
15-
}
2+
ESLint configuration for Javascript and TypeScript based SparkPost projects
3+
4+
## Upgrading from 2.x to 3.x
5+
There were several breaking changes including moving from ESLint 5.x to ESLint 8.x. This change alone caused some minimal breaking changes. Since
6+
we ultimately extend `eslint:recommended` in our base configuration, the upgrade from eslint 5.x to 8.x changed that 'recommended' config and the
7+
rules between versions have definitely changed. We compensated to match our existing config as best we could, but you may find other changes when
8+
running ESLint in your projects.
9+
10+
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,
11+
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
12+
so that we no longer need to install and maintain them in projects that don't use them.
13+
14+
### Special Concerns for Mocha Based Projects
15+
Traditionally we've setup special rules for `mocha` based projects, however not all projects use `mocha`. This would lead to dependencies being
16+
installed that were unrelated to the project. For this reason, we have split `mocha` configuration into its own configuration. You can take
17+
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
18+
dev dependencies.
19+
20+
Example:
21+
```shell
22+
npm i -D eslint-plugin-mocha
1623
```
17-
18-
19-
The scripts below in this README are purely for reference and can make managing documentation in your shared lib much easier.
20-
21-
### Useful NPM scripts
24+
In your `.eslintrc` file:
2225
```json
2326
{
24-
"scripts": {
25-
"chk-changelog": "grep `node -e 'console.log(require(\"./package.json\").version);'` CHANGELOG.md || echo 'Please update CHANGELOG.md with your updates'; exit 255",
26-
"docs": "doxdox index.js 'mocks/**/*.js' 'lib/**/*.js' --layout markdown --output DOCUMENTATION.md",
27-
"lint": "eslint . --fix",
28-
"nice-docs": "doxdox 'index.js' 'mocks/**/*.js' 'lib/**/*.js' --layout bootstrap --output docs/index.html && open docs/index.html",
29-
"prepublishOnly": "npm run chk-changelog",
30-
"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 "
31-
}
27+
"normal": "stuff <- comment",
28+
"overrides": [
29+
{
30+
"files": ["test/**/*.spec.js"],
31+
"extends": ["sparkpost/mocha"]
32+
}
33+
]
3234
}
3335
```
3436

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

41-
#### Add and modify the npm script.
42-
The list below (`index.js 'mocks/**/*.js 'lib/**/*.js`) will probably need to be changed for your lib.
43-
```json
44-
{
45-
"docs": "doxdox index.js 'mocks/**/*.js' 'lib/**/*.js' --layout markdown --output DOCUMENTATION.md"
46-
}
43+
Example:
44+
```shell
45+
npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-prettier
4746
```
48-
49-
#### Run the script
50-
```bash
51-
npm run docs
52-
```
53-
This will generate a ./DOCUMENTATION.md file that will include all JSDoc references in your module.
54-
55-
#### Auto generating the docs
56-
Given that you have husky installed, adding an npm script for `prepush` will automatically generate and commit docs anytime you push to git.
47+
In your `.eslintrc` file:
5748
```json
5849
{
59-
"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 "
50+
"normal": "stuff <- comment",
51+
"extends": ["sparkpost/typescript"],
52+
"rules": {
53+
"other": "rules that override the base typescript config <- comment"
54+
}
6055
}
6156
```
6257

63-
#### Generating nicer docs
64-
I recommend adding docs to your gitignore if its not already there.
65-
```bash
66-
echo docs >> .gitignore
67-
```
58+
## Docs in Libraries
59+
This config has extra rules specifically around JSDocs to help have better documentation in our libraries.
60+
This can help in knowledge sharing and will hopefully promote better docs in our shared JS modules.
6861

69-
Add the npm script:
62+
To use, add the following to your `.eslintrc` file:
7063
```json
7164
{
72-
"nice-docs": "doxdox 'index.js' 'mocks/**/*.js' 'lib/**/*.js' --layout bootstrap --output docs/index.html && open docs/index.html"
65+
"extends": "sparkpost/lib"
7366
}
7467
```
7568

76-
Run the npm script
77-
```bash
78-
npm run nice-docs
79-
```
80-
81-
### Checking Changelogs
69+
### Automation for Checking Changelogs
8270
#### Add the npm scripts
8371
```json
8472
{
8573
"chk-changelog": "grep `node -e 'console.log(require(\"./package.json\").version);'` CHANGELOG.md || echo 'Please update CHANGELOG.md with your updates'; exit 255",
8674
"prepublishOnly": "npm run chk-changelog"
8775
}
8876
```
89-
This will check your changelog for an entry for your current version when you publish.
77+
This will check your changelog for an entry for your current version when you publish.

api.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
module.exports = {
44
env: {
5-
node: true,
6-
mocha: true
5+
node: true
76
},
87
extends: 'sparkpost/index'
98
};

index.js

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module.exports = {
55
es6: true
66
},
77
parserOptions: {
8-
ecmaVersion: 2018
8+
ecmaVersion: 2021
99
},
10-
plugins: ['mocha'],
1110
extends: ['eslint:recommended'],
1211
rules: {
1312
'arrow-body-style': ['error', 'as-needed'],
@@ -30,10 +29,6 @@ module.exports = {
3029
'keyword-spacing': ['error', { before: true, after: true }],
3130
'linebreak-style': ['error', 'unix'],
3231
'max-params': ['error', 3],
33-
'mocha/no-exclusive-tests': 'error',
34-
'mocha/no-mocha-arrows': 'error',
35-
'mocha/no-identical-title': 'error',
36-
'mocha/no-sibling-hooks': 'error',
3732
'new-cap': 'error',
3833
'no-caller': 'error',
3934
quotes: ['error', 'single'],
@@ -76,51 +71,5 @@ module.exports = {
7671
'vars-on-top': 'error',
7772
'wrap-iife': ['error', 'any'],
7873
yoda: ['error', 'never']
79-
},
80-
overrides: [
81-
{
82-
files: ['*.spec.js'],
83-
rules: {
84-
'max-params': 'off',
85-
'func-names': 'off',
86-
'prefer-arrow-callback': 'off'
87-
}
88-
},
89-
{
90-
files: ['*.ts'],
91-
extends:
92-
[
93-
'plugin:@typescript-eslint/eslint-recommended',
94-
'plugin:@typescript-eslint/recommended',
95-
'prettier/@typescript-eslint',
96-
'plugin:prettier/recommended'
97-
],
98-
env: {
99-
es6: true
100-
},
101-
parser: '@typescript-eslint/parser',
102-
plugins: ['prettier', 'mocha', '@typescript-eslint'],
103-
rules: {
104-
'@typescript-eslint/no-explicit-any': 'error',
105-
'@typescript-eslint/camelcase': 'off',
106-
'@typescript-eslint/no-use-before-define': [
107-
'error',
108-
{
109-
functions: false,
110-
classes: false,
111-
variables: true
112-
}
113-
],
114-
'prettier/prettier': [
115-
'error',
116-
{
117-
semi: true,
118-
singleQuote: true,
119-
tabWidth: 2,
120-
trailingComma: 'none'
121-
}
122-
]
123-
}
124-
}
125-
]
74+
}
12675
};

mocha.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
module.exports = {
4+
env: {
5+
es6: true,
6+
node: true,
7+
mocha: true
8+
},
9+
parserOptions: {
10+
ecmaVersion: 2021
11+
},
12+
plugins: ['mocha'],
13+
extends: ['sparkpost/index'],
14+
rules: {
15+
'max-params': 'off',
16+
'func-names': 'off',
17+
'prefer-arrow-callback': 'off',
18+
'require-jsdoc': 'off',
19+
'valid-jsdoc': 'off',
20+
'mocha/no-exclusive-tests': 'error',
21+
'mocha/no-mocha-arrows': 'error',
22+
'mocha/no-identical-title': 'error',
23+
'mocha/no-sibling-hooks': 'error'
24+
}
25+
}

0 commit comments

Comments
 (0)