Skip to content

Commit e8617ad

Browse files
committed
lint and ci, the modern npm way
1 parent bdbf891 commit e8617ad

18 files changed

+9995
-6547
lines changed

.eslintrc.json

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2018,
4+
"ecmaFeatures": {},
5+
"sourceType": "script"
6+
},
7+
8+
"env": {
9+
"es6": true,
10+
"node": true
11+
},
12+
13+
"plugins": [
14+
"import",
15+
"node",
16+
"promise",
17+
"standard"
18+
],
19+
20+
"globals": {
21+
"document": "readonly",
22+
"navigator": "readonly",
23+
"window": "readonly"
24+
},
25+
26+
"rules": {
27+
"accessor-pairs": "error",
28+
"array-bracket-spacing": ["error", "never"],
29+
"arrow-spacing": ["error", { "before": true, "after": true }],
30+
"block-spacing": ["error", "always"],
31+
"brace-style": ["error", "1tbs", { "allowSingleLine": false }],
32+
"camelcase": ["error", { "properties": "never" }],
33+
"comma-dangle": ["error", {
34+
"arrays": "always-multiline",
35+
"objects": "always-multiline",
36+
"imports": "always-multiline",
37+
"exports": "always-multiline",
38+
"functions": "never"
39+
}],
40+
"comma-spacing": ["error", { "before": false, "after": true }],
41+
"comma-style": ["error", "last"],
42+
"computed-property-spacing": ["error", "never"],
43+
"constructor-super": "error",
44+
"curly": ["error", "multi-or-nest"],
45+
"dot-location": ["error", "property"],
46+
"dot-notation": ["error", { "allowKeywords": true }],
47+
"eol-last": "error",
48+
"eqeqeq": ["error", "always", { "null": "ignore" }],
49+
"func-call-spacing": ["error", "never"],
50+
"generator-star-spacing": ["error", { "before": true, "after": true }],
51+
"handle-callback-err": ["error", "^(err|error)$" ],
52+
"indent": ["error", 2, {
53+
"SwitchCase": 1,
54+
"VariableDeclarator": 1,
55+
"outerIIFEBody": 1,
56+
"MemberExpression": 1,
57+
"FunctionDeclaration": { "parameters": 1, "body": 1 },
58+
"FunctionExpression": { "parameters": 1, "body": 1 },
59+
"CallExpression": { "arguments": 1 },
60+
"ArrayExpression": 1,
61+
"ObjectExpression": 1,
62+
"ImportDeclaration": 1,
63+
"flatTernaryExpressions": true,
64+
"ignoreComments": false,
65+
"ignoredNodes": ["TemplateLiteral *"]
66+
}],
67+
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
68+
"keyword-spacing": ["error", { "before": true, "after": true }],
69+
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
70+
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, "properties": true }],
71+
"new-parens": "error",
72+
"no-array-constructor": "error",
73+
"no-async-promise-executor": "error",
74+
"no-caller": "error",
75+
"no-case-declarations": "error",
76+
"no-class-assign": "error",
77+
"no-compare-neg-zero": "error",
78+
"no-cond-assign": "off",
79+
"no-const-assign": "error",
80+
"no-constant-condition": ["error", { "checkLoops": false }],
81+
"no-control-regex": "error",
82+
"no-debugger": "error",
83+
"no-delete-var": "error",
84+
"no-dupe-args": "error",
85+
"no-dupe-class-members": "error",
86+
"no-dupe-keys": "error",
87+
"no-duplicate-case": "error",
88+
"no-empty-character-class": "error",
89+
"no-empty-pattern": "error",
90+
"no-eval": "error",
91+
"no-ex-assign": "error",
92+
"no-extend-native": "error",
93+
"no-extra-bind": "error",
94+
"no-extra-boolean-cast": "error",
95+
"no-extra-parens": ["error", "functions"],
96+
"no-fallthrough": "error",
97+
"no-floating-decimal": "error",
98+
"no-func-assign": "error",
99+
"no-global-assign": "error",
100+
"no-implied-eval": "error",
101+
"no-inner-declarations": ["error", "functions"],
102+
"no-invalid-regexp": "error",
103+
"no-irregular-whitespace": "error",
104+
"no-iterator": "error",
105+
"no-labels": ["error", { "allowLoop": true, "allowSwitch": false }],
106+
"no-lone-blocks": "error",
107+
"no-misleading-character-class": "error",
108+
"no-prototype-builtins": "error",
109+
"no-useless-catch": "error",
110+
"no-mixed-operators": "off",
111+
"no-mixed-spaces-and-tabs": "error",
112+
"no-multi-spaces": "error",
113+
"no-multi-str": "error",
114+
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
115+
"no-negated-in-lhs": "error",
116+
"no-new": "off",
117+
"no-new-func": "error",
118+
"no-new-object": "error",
119+
"no-new-require": "error",
120+
"no-new-symbol": "error",
121+
"no-new-wrappers": "error",
122+
"no-obj-calls": "error",
123+
"no-octal": "error",
124+
"no-octal-escape": "error",
125+
"no-path-concat": "error",
126+
"no-proto": "error",
127+
"no-redeclare": ["error", { "builtinGlobals": false }],
128+
"no-regex-spaces": "error",
129+
"no-return-assign": "off",
130+
"no-self-assign": "off",
131+
"no-self-compare": "error",
132+
"no-sequences": "error",
133+
"no-shadow-restricted-names": "error",
134+
"no-sparse-arrays": "error",
135+
"no-tabs": "error",
136+
"no-template-curly-in-string": "error",
137+
"no-this-before-super": "error",
138+
"no-throw-literal": "off",
139+
"no-trailing-spaces": "error",
140+
"no-undef": "error",
141+
"no-undef-init": "error",
142+
"no-unexpected-multiline": "error",
143+
"no-unmodified-loop-condition": "error",
144+
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
145+
"no-unreachable": "error",
146+
"no-unsafe-finally": 0,
147+
"no-unsafe-negation": "error",
148+
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
149+
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
150+
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
151+
"no-useless-call": "error",
152+
"no-useless-computed-key": "error",
153+
"no-useless-constructor": "error",
154+
"no-useless-escape": "error",
155+
"no-useless-rename": "error",
156+
"no-useless-return": "error",
157+
"no-void": "error",
158+
"no-whitespace-before-property": "error",
159+
"no-with": "error",
160+
"nonblock-statement-body-position": [2, "below"],
161+
"object-curly-newline": "off",
162+
"object-curly-spacing": "off",
163+
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
164+
"one-var": ["error", { "initialized": "never" }],
165+
"operator-linebreak": "off",
166+
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
167+
"prefer-const": ["error", {"destructuring": "all"}],
168+
"prefer-promise-reject-errors": "error",
169+
"quote-props": ["error", "as-needed"],
170+
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
171+
"rest-spread-spacing": ["error", "never"],
172+
"semi": ["error", "never"],
173+
"semi-spacing": ["error", { "before": false, "after": true }],
174+
"space-before-blocks": ["error", "always"],
175+
"space-before-function-paren": ["error", "always"],
176+
"space-in-parens": ["error", "never"],
177+
"space-infix-ops": "error",
178+
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
179+
"spaced-comment": ["error", "always", {
180+
"line": { "markers": ["*package", "!", "/", ",", "="] },
181+
"block": { "balanced": true, "markers": ["*package", "!", ",", ":", "::", "flow-include"], "exceptions": ["*"] }
182+
}],
183+
"symbol-description": "error",
184+
"template-curly-spacing": ["error", "never"],
185+
"template-tag-spacing": ["error", "never"],
186+
"unicode-bom": ["error", "never"],
187+
"use-isnan": "error",
188+
"valid-typeof": ["error", { "requireStringLiterals": true }],
189+
"wrap-iife": ["error", "any", { "functionPrototypeMethods": true }],
190+
"yield-star-spacing": ["error", "both"],
191+
"yoda": ["error", "never"],
192+
193+
"import/export": "error",
194+
"import/first": "error",
195+
"import/no-absolute-path": ["error", { "esmodule": true, "commonjs": true, "amd": false }],
196+
"import/no-duplicates": "error",
197+
"import/no-named-default": "error",
198+
"import/no-webpack-loader-syntax": "error",
199+
200+
"node/no-deprecated-api": "error",
201+
"node/process-exit-as-throw": "error",
202+
203+
"promise/param-names": "off",
204+
205+
"standard/no-callback-literal": "error"
206+
}
207+
}

.github/workflows/ci.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
################################################################################
3+
# Template - Node CI
4+
#
5+
# Description:
6+
# This contains the basic information to: install dependencies, run tests,
7+
# get coverage, and run linting on a nodejs project. This template will run
8+
# over the MxN matrix of all operating systems, and all current LTS versions
9+
# of NodeJS.
10+
#
11+
# Dependencies:
12+
# This template assumes that your project is using the `tap` module for
13+
# testing. If you're not using this module, then the step that runs your
14+
# coverage will need to be adjusted.
15+
#
16+
################################################################################
17+
name: Node CI
18+
19+
on: [push, pull_request]
20+
21+
jobs:
22+
build:
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
node-version: [10.x, 12.x, 13.x]
27+
os: [ubuntu-latest, windows-latest, macOS-latest]
28+
29+
runs-on: ${{ matrix.os }}
30+
31+
steps:
32+
# Checkout the repository
33+
- uses: actions/checkout@v2
34+
# Installs the specific version of Node.js
35+
- name: Use Node.js ${{ matrix.node-version }}
36+
uses: actions/setup-node@v1
37+
with:
38+
node-version: ${{ matrix.node-version }}
39+
40+
################################################################################
41+
# Install Dependencies
42+
#
43+
# ASSUMPTIONS:
44+
# - The project has a package-lock.json file
45+
#
46+
# Simply run the tests for the project.
47+
################################################################################
48+
- name: Install dependencies
49+
run: npm ci
50+
51+
################################################################################
52+
# Run Testing
53+
#
54+
# ASSUMPTIONS:
55+
# - The project has `tap` as a devDependency
56+
# - There is a script called "test" in the package.json
57+
#
58+
# Simply run the tests for the project.
59+
################################################################################
60+
- name: Run tests
61+
run: npm test -- --no-coverage
62+
63+
################################################################################
64+
# Run coverage check
65+
#
66+
# ASSUMPTIONS:
67+
# - The project has `tap` as a devDependency
68+
# - There is a script called "coverage" in the package.json
69+
#
70+
# Coverage should only be posted once, we are choosing the latest LTS of
71+
# node, and ubuntu as the matrix point to post coverage from. We limit
72+
# to the 'push' event so that coverage ins't posted twice from the
73+
# pull-request event, and push event (line 3).
74+
################################################################################
75+
- name: Run coverage report
76+
if: github.event_name == 'push' && matrix.node-version == '12.x' && matrix.os == 'ubuntu-latest'
77+
run: npm test
78+
env:
79+
# The environment variable name is leveraged by `tap`
80+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
81+
82+
################################################################################
83+
# Run linting
84+
#
85+
# ASSUMPTIONS:
86+
# - There is a script called "lint" in the package.json
87+
#
88+
# We run linting AFTER we run testing and coverage checks, because if a step
89+
# fails in an GitHub Action, all other steps are not run. We don't want to
90+
# fail to run tests or coverage because of linting. It should be the lowest
91+
# priority of all the steps.
92+
################################################################################
93+
- name: Run linter
94+
run: npm run lint

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# npm-registry-fetch
22

3-
[![npm version](https://img.shields.io/npm/v/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch)
4-
[![license](https://img.shields.io/npm/l/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch)
5-
[![Travis](https://img.shields.io/travis/npm/npm-registry-fetch/latest.svg)](https://travis-ci.org/npm/npm-registry-fetch)
6-
[![AppVeyor](https://img.shields.io/appveyor/ci/npm/npm-registry-fetch/latest.svg)](https://ci.appveyor.com/project/npm/npm-registry-fetch)
7-
[![Coverage Status](https://coveralls.io/repos/github/npm/npm-registry-fetch/badge.svg?branch=latest)](https://coveralls.io/github/npm/npm-registry-fetch?branch=latest)
8-
93
[`npm-registry-fetch`](https://github.com/npm/npm-registry-fetch) is a Node.js
104
library that implements a `fetch`-like API for accessing npm registry APIs
115
consistently. It's able to consume npm-style configuration values and has all

appveyor.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

auth.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const url = require('url')
55

66
module.exports = getAuth
77
function getAuth (registry, opts_ = {}) {
8-
if (!registry) { throw new Error('registry is required') }
8+
if (!registry)
9+
throw new Error('registry is required')
910
const opts = opts_.forceAuth ? opts_.forceAuth : { ...defaultOpts, ...opts_ }
1011
const AUTH = {}
1112
const regKey = registry && registryKey(registry)
@@ -19,9 +20,9 @@ function getAuth (registry, opts_ = {}) {
1920
doKey('_auth')
2021
doKey('otp')
2122
doKey('always-auth', 'alwaysAuth')
22-
if (AUTH.password) {
23+
if (AUTH.password)
2324
AUTH.password = Buffer.from(AUTH.password, 'base64').toString('utf8')
24-
}
25+
2526
if (AUTH._auth && !(AUTH.username && AUTH.password)) {
2627
let auth = Buffer.from(AUTH._auth, 'base64').toString()
2728
auth = auth.split(':')
@@ -33,12 +34,11 @@ function getAuth (registry, opts_ = {}) {
3334
}
3435

3536
function addKey (opts, obj, scope, key, objKey) {
36-
if (opts[key]) {
37+
if (opts[key])
3738
obj[objKey || key] = opts[key]
38-
}
39-
if (scope && opts[`${scope}:${key}`]) {
39+
40+
if (scope && opts[`${scope}:${key}`])
4041
obj[objKey || key] = opts[`${scope}:${key}`]
41-
}
4242
}
4343

4444
// Called a nerf dart in the main codebase. Used as a "safe"
@@ -49,7 +49,7 @@ function registryKey (registry) {
4949
protocol: parsed.protocol,
5050
host: parsed.host,
5151
pathname: parsed.pathname,
52-
slashes: true
52+
slashes: true,
5353
})
5454
return url.format(new url.URL('.', formatted)).replace(/^[^:]+:/, '')
5555
}

0 commit comments

Comments
 (0)