Skip to content

Commit 008e0d3

Browse files
author
Mike Shaw
committed
feat(eslint): add default eslint rules
Signed-off-by: Mike Shaw <mike.shaw@dwp.gsi.gov.uk>
0 parents  commit 008e0d3

20 files changed

+7730
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require( '@dwp/eslint-config-base' );

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
node_modules
3+
.sonarlint
4+
.nyc_output
5+
.coverage
6+
.scannerwork
7+
dwp-eslint-config-mocha-*.tgz

.gitlab-ci.yml

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
.executor-shell: &executor-shell
2+
tags:
3+
- shell
4+
5+
.nvm-use: &nvm-use
6+
before_script:
7+
- nvm use
8+
9+
.dependency-npm: &dependency-npm
10+
dependencies:
11+
- npm
12+
13+
.dependency-unit: &dependency-unit
14+
dependencies:
15+
- npm
16+
- unit
17+
18+
.only-branches: &only-branches
19+
except:
20+
- master
21+
- develop
22+
- tags
23+
- triggers
24+
25+
.not-branches: &not-branches
26+
only:
27+
- master
28+
- develop
29+
- tags
30+
31+
stages:
32+
- setup
33+
- build
34+
- compliance-tests
35+
- security-tests
36+
- unit-tests
37+
- quality-tests
38+
39+
nvm:
40+
stage: setup
41+
<<: *executor-shell
42+
script:
43+
- nvm install
44+
45+
npm:
46+
stage: build
47+
<<: *executor-shell
48+
<<: *nvm-use
49+
script:
50+
- HASH=( $( md5sum package.json ) )
51+
- CACHE=/tmp/${CI_PROJECT_NAME}_${HASH}.tgz
52+
- if [ -f $CACHE ]; then
53+
tar -xzf $CACHE;
54+
else
55+
rm -f /tmp/${CI_PROJECT_NAME}_*.tgz &&
56+
npm install &&
57+
tar -czf $CACHE node_modules;
58+
fi
59+
artifacts:
60+
name: "${CI_PROJECT_NAME}_${CI_JOB_ID}_${CI_COMMIT_SHA}"
61+
expire_in: 10 mins
62+
paths:
63+
- node_modules
64+
65+
commitlint-branch:
66+
stage: compliance-tests
67+
<<: *executor-shell
68+
<<: *nvm-use
69+
<<: *dependency-npm
70+
script:
71+
- git fetch origin develop --quiet
72+
- git checkout develop --quiet
73+
- git reset --hard origin/develop --quiet
74+
- git checkout - --quiet
75+
- npm run compliance:commitlint
76+
<<: *only-branches
77+
78+
commitlint-develop:
79+
stage: compliance-tests
80+
<<: *executor-shell
81+
<<: *nvm-use
82+
<<: *dependency-npm
83+
script:
84+
- git fetch origin master --quiet
85+
- git checkout master --quiet
86+
- git reset --hard origin/master --quiet
87+
- git checkout - --quiet
88+
- ./node_modules/.bin/commitlint --from=master --to=HEAD
89+
<<: *not-branches
90+
91+
eslint:
92+
stage: compliance-tests
93+
<<: *executor-shell
94+
<<: *nvm-use
95+
<<: *dependency-npm
96+
script:
97+
- npm run compliance:eslint
98+
99+
outdated:
100+
stage: security-tests
101+
<<: *executor-shell
102+
<<: *nvm-use
103+
<<: *dependency-npm
104+
script:
105+
- npm outdated
106+
allow_failure: true
107+
108+
nsp:
109+
stage: security-tests
110+
<<: *executor-shell
111+
<<: *nvm-use
112+
script:
113+
- npm run security:nsp
114+
115+
unit:
116+
stage: unit-tests
117+
<<: *executor-shell
118+
<<: *nvm-use
119+
<<: *dependency-npm
120+
script:
121+
- npm run unit:test
122+
artifacts:
123+
expire_in: 10 mins
124+
paths:
125+
- .coverage/unit/lcov.info
126+
coverage: /^Lines\s*:\s(\d+(?:.\d+)?%)/
127+
128+
sonarjs:
129+
stage: quality-tests
130+
<<: *executor-shell
131+
<<: *nvm-use
132+
<<: *dependency-npm
133+
script:
134+
- npm run quality:sonarjs
135+
136+
sonar-scanner:
137+
stage: quality-tests
138+
<<: *executor-shell
139+
<<: *nvm-use
140+
<<: *dependency-unit
141+
script:
142+
- sed -i.bak -e "s|^SF:\(.*/[[:digit:]]\{1,\}/.*/\)|SF:$( pwd )/|g" .coverage/unit/lcov.info
143+
- npm run quality:sonar-scanner
144+
<<: *not-branches

.lintstagedrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"*.js": "eslint",
3+
"package.json": [ "security:outdated", "security:nsp" ]
4+
}

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact true

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9.4.0

.nycrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@dwp/nyc-config-base"
3+
}

.snyk

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.10.1
3+
ignore: {}
4+
patch: {}

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4+
5+
<a name="1.0.0"></a>
6+
# 1.0.0 (2018-05-02)
7+
8+
9+
### Features
10+
11+
* **eslint:** add default eslint rules

CONTRIBUTING.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Contributing
2+
3+
We're glad you want to contribute to this project! This document will help answer common questions you may have during your first contribution.
4+
5+
## Submitting Issues
6+
7+
Not every contribution comes in the form of code. Submitting, confirming, and triaging issues is an important task for any project.
8+
9+
If you are familiar with DWP and know the component that is causing you a problem, you can file an issue in the corresponding GitHub project. All of our Open Source Software can be found in our [GitHub organization](https://github.com/dwp/).
10+
11+
We ask you not to submit security concerns via GitHub. For details on submitting potential security issues please contact [technology.boss@dwp.gsi.gov.uk](mailto:technology.boss@dwp.gsi.gov.uk)
12+
13+
## Contribution Process
14+
15+
We have a 3 step process for contributions:
16+
17+
1. Fork our repo and commit changes to a new branch based off `develop`, making sure to sign-off those changes for the [Developer Certificate of Origin](#developer-certification-of-origin-dco).
18+
2. Create a GitHub Pull Request for your change, following the instructions in the pull request template (if present).
19+
3. A [Code Review](#code-review-process) will then be undertaken by the project maintainers.
20+
21+
### Pull Request Requirements
22+
23+
Our projects are built to last. We strive to ensure high quality throughout the experience. In order to ensure this, we require that all pull requests to DWP projects meet these specifications:
24+
25+
1. **Tests:** To ensure high quality code and protect against future regressions, we require all the code in DWP Projects to have at least unit test coverage.
26+
2. **Green CI Tests:** We use CI systems to test all pull requests, although not all of these are publicly visible. We require these test runs to succeed on every pull request before being merged. Project maintainers will help guide you if they find any issues.
27+
28+
### Code Review Process
29+
30+
Code review for public contributions takes place in GitHub pull requests. See [this article](https://help.github.com/articles/about-pull-requests/) if you're not familiar with GitHub Pull Requests.
31+
32+
Once you open a pull request, project maintainers will review your code and respond to your pull request with any feedback they might have. The process at this point is as follows:
33+
34+
1. Two thumbs-up (:+1:) are required from project maintainers.
35+
2. When ready, your pull request will be tagged with label `Ready For Merge`.
36+
3. Your change will be merged into the project's `develop` branch and may be noted in the project's `CHANGELOG.md` at the time of release.
37+
38+
### Developer Certification of Origin (DCO)
39+
40+
Licensing is very important to open source projects. It helps ensure the software continues to be available under the terms that the author desired.
41+
42+
This project uses [the ISC license](LICENSE) to strike a balance between open contribution and allowing you to use the software however you would like to.
43+
44+
The license tells you what rights you have that are provided by the copyright holder. It is important that the contributor fully understands what rights they are licensing and agrees to them. Sometimes the copyright holder isn't the contributor, such as when the contributor is doing work on behalf of a company.
45+
46+
To make a good faith effort to ensure these criteria are met, DWP requires the Developer Certificate of Origin (DCO) process to be followed.
47+
48+
The DCO is an attestation attached to every contribution made by every developer. In the commit message of the contribution, the developer simply adds a Signed-off-by statement and thereby agrees to the DCO, which you can find below or at <http://developercertificate.org/>.
49+
50+
```
51+
Developer's Certificate of Origin 1.1
52+
53+
By making a contribution to this project, I certify that:
54+
55+
(a) The contribution was created in whole or in part by me and I
56+
have the right to submit it under the open source license
57+
indicated in the file; or
58+
59+
(b) The contribution is based upon previous work that, to the
60+
best of my knowledge, is covered under an appropriate open
61+
source license and I have the right under that license to
62+
submit that work with modifications, whether created in whole
63+
or in part by me, under the same open source license (unless
64+
I am permitted to submit under a different license), as
65+
Indicated in the file; or
66+
67+
(c) The contribution was provided directly to me by some other
68+
person who certified (a), (b) or (c) and I have not modified
69+
it.
70+
71+
(d) I understand and agree that this project and the contribution
72+
are public and that a record of the contribution (including
73+
all personal information I submit with it, including my
74+
sign-off) is maintained indefinitely and may be redistributed
75+
consistent with this project or the open source license(s)
76+
involved.
77+
```
78+
79+
#### DCO Sign-Off Methods
80+
81+
The DCO requires a sign-off message in the following format appear on each commit in the pull request:
82+
83+
```
84+
Signed-off-by: Jane Doe <jane.doe@example.com>
85+
```
86+
87+
The DCO text can either be manually added to your commit body, or you can add either **-signoff** or **-s** to your usual git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running **git commit –-amend --signoff --no-edit**. If you've pushed your changes to GitHub already you'll need to force push your branch after this with **git push --force**.
88+
89+
## Versioning
90+
91+
We follow the [Semantic Versioning](http://semver.org/) standard. Our standard version numbers look like X.Y.Z which mean:
92+
93+
* X is a major release, which may not be fully compatible with any prior major releases
94+
* Y is a minor release, which adds both new features and bug fixes
95+
* Z is a patch release, which just adds bug fixes
96+
97+
## Acknowledgements
98+
99+
This guide was originally based upon the [InSpec Contribution Guide](https://github.com/chef/inspec/blob/master/CONTRIBUTING.md).

LICENSE

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License (ISC)
2+
3+
Copyright 2017, 2018 Crown Copyright (Department for Work and Pensions)
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
PERFORMANCE OF THIS SOFTWARE.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @dwp/eslint-config-mocha
2+
3+
Shareable [`eslint`](http://eslint.org) config enforcing our lint and style convention for the [`mocha`](https://mocha.github.io/) test framework.
4+
5+
## Getting started
6+
7+
```sh
8+
npm install --save-dev @dwp/eslint-config-base eslint
9+
```
10+
11+
## Rules
12+
13+
Add an `.eslintrc.js` file that looks something like:
14+
15+
```js
16+
module.exports = require( '@dwp/eslint-config-mocha' );
17+
```
18+
19+
You can add your own rules to enhance this, but in doing so please ensure you don't weaken the baseline ruleset.
20+
21+
Don't use `.eslintrc` (low precedence) or `package.json` (even lower, and just plain bad!), lest you incur the wrath of a patient adversary.
22+
23+
## Linting
24+
25+
Add `eslint` to your test suite like this, or see our [package.json](package.json) for an example of how we do it:
26+
27+
```json
28+
"test": "eslint ."
29+
```

commitlint.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
module.exports = require('@dwp/commitlint-config-base');

0 commit comments

Comments
 (0)