Skip to content

Commit 7edf5a6

Browse files
authored
refactor(helpers): reduce complexity
### Summary of changes 1. test(qa): add sonar scanning - Add `sonarqube-scanner` for PR and Refactoring templates - Add `dotenv-extended` for 12-factor-style config strategy - Replace all copy/paste repo refs with this org/repo 1. test(config): cover env-config 1. refactor(complexity): remove unused functions - Replace all possible "lodash.is*" functions with "@sindresorhus/is.*" - Remove unused lodash dependencies - Reduce variable-factory's cyclomatic complexity 1. docs(readme): fix appveyor badge 1. ci(travis): fix npm-script 1. ci(windows): modify test config and expectations - Appveyor is not configured to load secret environment variables, so simply check to ensure the key counts match. - Appveyor doesn't have as many ENV VARs, so assert with "toBeLessThanOrEqual". Closes #4 Closes #6
1 parent 718e249 commit 7edf5a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+10254
-646
lines changed

.env.defaults

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# .env.defaults, committed to repo
2+
3+
## See https://github.com/keithmorris/node-dotenv-extended/#readme
4+
## ⛔️
5+
## 🚫 DO NOT COMMIT YOUR ACTUAL .env file to version control.
6+
## 🚫 It should only include environment-specific values such
7+
## 🚫 as database passwords or API keys.
8+
## 🚫 Your production database should have a different password
9+
## 🚫 than your development database.
10+
11+
#
12+
# Product manifest (package.json) variables
13+
#
14+
15+
NPM_PACKAGE_NAME=archetypes-rules
16+
NPM_PACKAGE_VERSION=
17+
18+
#
19+
# Gitlab variable defaults
20+
#
21+
22+
GITLAB_ENDPOINT=https://github.com/api/v4
23+
GITLAB_JSON_OUTPUT=true
24+
GITLAB_PROJECT_ID=10416318
25+
GITLAB_REF=master
26+
GITLAB_RESOLVE_BODY_ONLY=true
27+
GITLAB_RESOURCE=signatures.json
28+
GITLAB_TOKEN=
29+
K8S_SECRET_GITLAB_TOKEN=
30+
31+
#
32+
# Jest JUnit for JavaScript BDD test suites
33+
# @see https://github.com/jest-community/jest-junit#configuration
34+
#
35+
36+
# name attribute of <testsuites>
37+
# @default "jest tests"
38+
JEST_SUITE_NAME=archetypes-rules tests
39+
40+
# File path to save the output.
41+
# @default "./junit.xml"
42+
JEST_JUNIT_OUTPUT=./jest-junit.xml
43+
44+
# Directory to save the output.
45+
# null
46+
JEST_JUNIT_OUTPUT_DIR=
47+
48+
# File name for the output.
49+
# @default "./junit.xml"
50+
JEST_JUNIT_OUTPUT_NAME=./jest-junit.xml
51+
52+
# Template string for name attribute of the <testsuite>.
53+
# @default "{title}"
54+
JEST_JUNIT_SUITE_NAME=
55+
56+
# Template string for the classname attribute of <testcase>.
57+
# @default "{classname} {title}"
58+
JEST_JUNIT_CLASSNAME=
59+
60+
# Template string for the name attribute of <testcase>.
61+
# @default "{classname} {title}"
62+
JEST_JUNIT_TITLE=
63+
64+
# Character(s) used to join the describe blocks.
65+
# @default " "
66+
JEST_JUNIT_ANCESTOR_SEPARATOR=
67+
68+
# DEPRECATED. Use suiteNameTemplate instead. Use file path as the name attribute of <testsuite>
69+
# @default "false"
70+
JEST_USE_PATH_FOR_SUITE_NAME=
71+
72+
#
73+
# SonarCloud variable defaults
74+
#
75+
76+
# SonarCloud static code analysis
77+
SONAR_BRANCH_TARGET=master
78+
SONAR_HOST_URL=https://sonarcloud.io
79+
SONAR_ORGANIZATION=commonality
80+
SONAR_PROJECT_KEY=commonality_archetypes-rules
81+
SONAR_PROJECT_NAME=archetypes-rules
82+
SONAR_PROJECT_VERSION=$SONAR_PROJECT_VERSION
83+
SONAR_TOKEN=
84+
K8S_SECRET_SONAR_TOKEN=

.env.schema

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# .env.schema, committed to repo
2+
3+
## See https://github.com/keithmorris/node-dotenv-extended/#readme
4+
## ⛔️
5+
## 🚫 DO NOT COMMIT YOUR ACTUAL .env file to version control.
6+
## 🚫 It should only include environment-specific values such
7+
## 🚫 as database passwords or API keys.
8+
## 🚫 Your production database should have a different password
9+
## 🚫 than your development database.
10+
11+
NODE_ENV=
12+
13+
#
14+
# Product manifest (package.json) variables
15+
#
16+
17+
NPM_PACKAGE_NAME=
18+
NPM_PACKAGE_VERSION=
19+
20+
#
21+
# Gitlab variables
22+
#
23+
24+
GITLAB_ENDPOINT=
25+
GITLAB_PROJECT_ID=
26+
# The name of the branch, tag, or commit SHA with the signatures.json resource.
27+
GITLAB_REF=
28+
GITLAB_RESOURCE=
29+
GITLAB_TOKEN=
30+
K8S_SECRET_GITLAB_TOKEN=
31+
32+
#
33+
# Jest JUnit for JavaScript BDD test suites
34+
# @see https://github.com/jest-community/jest-junit#configuration
35+
#
36+
37+
# name attribute of <testsuites>
38+
# @default "jest tests"
39+
JEST_SUITE_NAME=
40+
41+
# File path to save the output.
42+
# @default "./junit.xml"
43+
JEST_JUNIT_OUTPUT=
44+
45+
# Directory to save the output.
46+
# null
47+
JEST_JUNIT_OUTPUT_DIR=
48+
49+
# File name for the output.
50+
# @default "./junit.xml"
51+
JEST_JUNIT_OUTPUT_NAME=
52+
53+
# Template string for name attribute of the <testsuite>.
54+
# @default "{title}"
55+
JEST_JUNIT_SUITE_NAME=
56+
57+
# Template string for the classname attribute of <testcase>.
58+
# @default "{classname} {title}"
59+
JEST_JUNIT_CLASSNAME=
60+
61+
# Template string for the name attribute of <testcase>.
62+
# @default "{classname} {title}"
63+
JEST_JUNIT_TITLE=
64+
65+
# Character(s) used to join the describe blocks.
66+
# @default " "
67+
JEST_JUNIT_ANCESTOR_SEPARATOR=
68+
69+
# DEPRECATED. Use suiteNameTemplate instead. Use file path as the name attribute of <testsuite>
70+
# @default "false"
71+
JEST_USE_PATH_FOR_SUITE_NAME=
72+
73+
#
74+
# SonarCloud variables (CI/CD code analysis)
75+
#
76+
77+
# Name of the current working branch.
78+
# This is a short-lived branch
79+
# corresponding to Merge/Pull Requests, feature, and fix branches.
80+
# To get the current working branch name, run:
81+
# npm --loglevel silent run vars:git:branch:name
82+
# @see https://sonarcloud.io/documentation/branches/overview/
83+
84+
SONAR_BRANCH_NAME=
85+
86+
# The default branch of the repository; it should almost always
87+
# be "master".
88+
89+
SONAR_BRANCH_TARGET=
90+
SONAR_DATA_LOSS_SIGNATURES_TOKEN=
91+
SONAR_HOST_URL=
92+
SONAR_ORGANIZATION=
93+
SONAR_PROJECT_DESCRIPTION=
94+
SONAR_PROJECT_KEY=
95+
SONAR_PROJECT_NAME=
96+
SONAR_PROJECT_VERSION=
97+
SONAR_TOKEN=
98+
K8S_SECRET_SONAR_TOKEN=

.github/.keep

Whitespace-only changes.

.github/ISSUE_TEMPLATE/refactoring-proposal.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -49,43 +49,43 @@ assignees: ''
4949
<!-- SonarCloud badge refs -->
5050

5151
[sonar-alert-status-badge]:
52-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=alert_status&template=FLAT
52+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=alert_status&template=FLAT
5353
[sonar-alert-status-url]:
54-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
54+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
5555
[sonar-bugs-badge]:
56-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=bugs&template=FLAT
57-
[sonar-bugs-url]: https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
56+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=bugs&template=FLAT
57+
[sonar-bugs-url]: https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
5858
[sonar-code-smells-badge]:
59-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=code_smells&template=FLAT
59+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=code_smells&template=FLAT
6060
[sonar-code-smells-url]:
61-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
61+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
6262
[sonar-coverage-badge]:
63-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=coverage&template=FLAT
64-
[sonar-coverage-url]: https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
63+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=coverage&template=FLAT
64+
[sonar-coverage-url]: https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
6565
[sonar-duplicated-lines-density-badge]:
66-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=duplicated_lines_density&template=FLAT
66+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=duplicated_lines_density&template=FLAT
6767
[sonar-duplicated-lines-density-url]:
68-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
68+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
6969
[sonar-ncloc-badge]:
70-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=ncloc&template=FLAT
71-
[sonar-ncloc-url]: https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
70+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=ncloc&template=FLAT
71+
[sonar-ncloc-url]: https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
7272
[sonar-reliability-rating-badge]:
73-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=reliability_rating&template=FLAT
73+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=reliability_rating&template=FLAT
7474
[sonar-reliability-rating-url]:
75-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
75+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
7676
[sonar-security-rating-badge]:
77-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=security_rating&template=FLAT
77+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=security_rating&template=FLAT
7878
[sonar-security-rating-url]:
79-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
79+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
8080
[sonar-sqale-index-badge]:
81-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=sqale_index&template=FLAT
81+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=sqale_index&template=FLAT
8282
[sonar-sqale-index-url]:
83-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
83+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
8484
[sonar-sqale-rating-badge]:
85-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=sqale_rating&template=FLAT
85+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=sqale_rating&template=FLAT
8686
[sonar-sqale-rating-url]:
87-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
87+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules
8888
[sonar-vulnerabilities-badge]:
89-
https://sonarcloud.io/api/project_badges/measure?project=archetypes-rules-gitlab&metric=vulnerabilities&template=FLAT
89+
https://sonarcloud.io/api/project_badges/measure?project=commonality_archetypes-rules&metric=vulnerabilities&template=FLAT
9090
[sonar-vulnerabilities-url]:
91-
https://sonarcloud.io/dashboard?id=archetypes-rules-gitlab
91+
https://sonarcloud.io/dashboard?id=commonality_archetypes-rules

.github/ci/qa/sonar-scan.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const envConfig = require('../../../lib/env-config')
2+
const { description, name, version } = require('../../../package.json')
3+
const gitRepoInfo = require('git-repo-info')
4+
const sonarqubeScanner = require('sonarqube-scanner').customScanner
5+
6+
const { branch } = gitRepoInfo()
7+
8+
const sonarAnalysisParams = {
9+
SONAR_BRANCH_NAME: branch,
10+
SONAR_PROJECT_DESCRIPTION: description,
11+
SONAR_PROJECT_NAME: name,
12+
SONAR_PROJECT_VERSION: version
13+
}
14+
15+
const callback = platformExecutableOrCommand => {
16+
const SUCCESS = 0
17+
const FAILURE = 2
18+
let exitCode = SUCCESS
19+
try {
20+
console.log(platformExecutableOrCommand)
21+
} catch (err) {
22+
console.error(err)
23+
exitCode = FAILURE
24+
} finally {
25+
process.exit(exitCode)
26+
}
27+
}
28+
29+
const token =
30+
envConfig.K8S_SECRET_SONAR_TOKEN ||
31+
envConfig.SONAR_TOKEN ||
32+
process.env.K8S_SECRET_SONAR_TOKEN ||
33+
process.env.SONAR_TOKEN
34+
35+
const options = {
36+
'sonar.eslint.reportPaths': 'eslint-report.json',
37+
'sonar.javascript.exclusions': 'coverage/**,**/__tests__/**/*,lib/env-config.js',
38+
'sonar.javascript.lcov.reportPaths': 'coverage/lcov.info',
39+
'sonar.links.ci': 'https://travis-ci.com/commonality/archetypes-rules',
40+
'sonar.links.homepage':
41+
'https://github.com/commonality/archetypes-rules#readme',
42+
'sonar.links.issue': 'https://github.com/commonality/archetypes-rules/issues',
43+
'sonar.links.scm': 'https://github.com/commonality/archetypes-rules',
44+
'sonar.login': token,
45+
'sonar.organization': envConfig.SONAR_ORGANIZATION,
46+
'sonar.projectDescription': sonarAnalysisParams.SONAR_PROJECT_DESCRIPTION,
47+
'sonar.projectKey': envConfig.SONAR_PROJECT_KEY,
48+
'sonar.projectName': sonarAnalysisParams.SONAR_PROJECT_NAME,
49+
'sonar.projectVersion': sonarAnalysisParams.SONAR_PROJECT_VERSION,
50+
'sonar.sourceEncoding': 'UTF-8',
51+
'sonar.sources': 'lib',
52+
'sonar.test.inclusions': 'lib/**/*.test.js',
53+
'sonar.testExecutionReportPaths': 'sonar-test-report.xml',
54+
'sonar.tests': 'lib'
55+
}
56+
57+
if (process.env.TRAVIS_PULL_REQUEST) {
58+
Object.assign(options, {
59+
'sonar.pullrequest.base': 'master',
60+
'sonar.pullrequest.branch': sonarAnalysisParams.SONAR_BRANCH_NAME,
61+
'sonar.pullrequest.key': process.env.TRAVIS_PULL_REQUEST
62+
})
63+
}
64+
65+
// Run the scanner
66+
sonarqubeScanner(
67+
{
68+
serverUrl: envConfig.SONAR_HOST_URL,
69+
token,
70+
options
71+
},
72+
callback
73+
)

.github/PULL_REQUEST_TEMPLATE/pull_request_template.md .github/pull_request_template.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ _Why:_
8181

8282
### How to format, lint, and test your changes
8383

84-
Open a Terminal, go to the root directory for **data-loss-signatures**, and run:
84+
Open a Terminal, go to the root directory for **archetypes-rules**, and run:
8585

8686
```bash
8787
$ npm test
@@ -93,6 +93,11 @@ $ npm test
9393
> ![alert][octicon-alert] **_All_ tasks _must_ be completed** and **verified**
9494
> before a PR may be merged into <samp>master</samp>, however.
9595
96+
### How to test a release
97+
98+
The [Pre-release test instructions](https://github.com/commonality/archetypes-rules/wiki/Pre-release-test-instructions) include step-by-step guidelines for bundling, packing, and testing this module as it would be released on NPM.
99+
100+
96101
---
97102

98103
<!-- SonarCloud badge refs -->
@@ -157,9 +162,9 @@ $ npm test
157162

158163
[standardjs-logo]: https://cdn.rawgit.com/feross/standard/master/badge.svg
159164
[standardjs-url]: https://github.com/feross/standard
160-
[eslint-logo]: docs/img/logos/logo-eslint.png
165+
[eslint-logo]: https://raw.githubusercontent.com/commonality/archetypes-rules/master/docs/img/logos/logo-eslint.png
161166
[eslint-url]: https://eslint.org/docs/user-guide/getting-started
162-
[jest-logo]: docs/img/logo-jest.png
167+
[jest-logo]: https://raw.githubusercontent.com/commonality/archetypes-rules/master/docs/img/logos/logo-jest.png
163168
[jest-url]: https://facebook.github.io/jest/docs/en/getting-started.html
164169

165170
<!-- ⛔️ Octicon img references ⛔️ -->

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,37 @@ lib/variable/helpers/evaluate-quantity.js
163163
!.vscode/tasks.json
164164
!.vscode/launch.json
165165
!.vscode/extensions.json
166+
167+
# Sonar
168+
.scannerwork/
169+
sonar-test-report.xml
170+
eslint-report.json
171+
junit.xml
172+
173+
# General
174+
.DS_Store
175+
.AppleDouble
176+
.LSOverride
177+
178+
# Icon must end with two \r
179+
Icon
180+
181+
182+
# Thumbnails
183+
._*
184+
185+
# Files that might appear in the root of a volume
186+
.DocumentRevisions-V100
187+
.fseventsd
188+
.Spotlight-V100
189+
.TemporaryItems
190+
.Trashes
191+
.VolumeIcon.icns
192+
.com.apple.timemachine.donotpresent
193+
194+
# Directories potentially created on remote AFP share
195+
.AppleDB
196+
.AppleDesktop
197+
Network Trash Folder
198+
Temporary Items
199+
.apdisk

0 commit comments

Comments
 (0)