Skip to content

Commit 962678f

Browse files
authored
Add and configure ESLint and update configuration for Prettier (#703)
* Add ESLinter and update Prettier * Update eslint config * Update dependencies * Rebuild action * Update package.json * Updates docs * Update docs
1 parent 7c29869 commit 962678f

31 files changed

+3949
-1690
lines changed

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore list
2+
/*
3+
4+
# Do not ignore these folders:
5+
!__tests__/
6+
!src/

.eslintrc.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:@typescript-eslint/recommended',
5+
'plugin:eslint-plugin-jest/recommended',
6+
'eslint-config-prettier'
7+
],
8+
parser: '@typescript-eslint/parser',
9+
plugins: ['@typescript-eslint', 'eslint-plugin-jest'],
10+
rules: {
11+
'@typescript-eslint/no-require-imports': 'error',
12+
'@typescript-eslint/no-non-null-assertion': 'off',
13+
'@typescript-eslint/no-explicit-any': 'off',
14+
'@typescript-eslint/no-empty-function': 'off',
15+
'@typescript-eslint/ban-ts-comment': [
16+
'error',
17+
{
18+
'ts-ignore': 'allow-with-description'
19+
}
20+
],
21+
'no-console': 'error',
22+
'yoda': 'error',
23+
'prefer-const': [
24+
'error',
25+
{
26+
destructuring: 'all'
27+
}
28+
],
29+
'no-control-regex': 'off',
30+
'no-constant-condition': ['error', {checkLoops: false}]
31+
},
32+
overrides: [
33+
{
34+
files: ['**/*{test,spec}.ts'],
35+
rules: {
36+
'@typescript-eslint/no-unused-vars': 'off',
37+
'jest/no-standalone-expect': 'off',
38+
'jest/no-conditional-expect': 'off',
39+
'no-console': 'off',
40+
41+
}
42+
}
43+
],
44+
env: {
45+
node: true,
46+
es6: true,
47+
'jest/globals': true
48+
}
49+
};

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
* text=auto eol=lf
12
.licenses/** -diff linguist-generated=true

.github/ISSUE_TEMPLATE/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
blank_issues_enabled: false
1+
blank_issues_enabled: false

.github/workflows/basic-validation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ on:
1414
jobs:
1515
call-basic-validation:
1616
name: Basic validation
17-
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
17+
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main

.github/workflows/check-dist.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ on:
1414
jobs:
1515
call-check-dist:
1616
name: Check dist/
17-
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
17+
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main

.github/workflows/codeql-analysis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: CodeQL analysis
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
schedule:
99
- cron: '0 3 * * 0'
1010

1111
jobs:
1212
call-codeQL-analysis:
13-
name: CodeQL analysis
14-
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
13+
name: CodeQL analysis
14+
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main

.github/workflows/release-new-action-version.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
name: releaseNewActionVersion
2222
runs-on: ubuntu-latest
2323
steps:
24-
- name: Update the ${{ env.TAG_NAME }} tag
25-
uses: actions/[email protected]
26-
with:
27-
source-tag: ${{ env.TAG_NAME }}
28-
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
24+
- name: Update the ${{ env.TAG_NAME }} tag
25+
uses: actions/[email protected]
26+
with:
27+
source-tag: ${{ env.TAG_NAME }}
28+
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

.github/workflows/versions.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ jobs:
5757
fail-fast: false
5858
matrix:
5959
os: [ubuntu-latest, windows-latest, macos-latest]
60-
node-version: ['20-v8-canary', '20.0.0-v8-canary','20.0.0-v8-canary20221103f7e2421e91']
60+
node-version:
61+
[
62+
'20-v8-canary',
63+
'20.0.0-v8-canary',
64+
'20.0.0-v8-canary20221103f7e2421e91'
65+
]
6166
steps:
6267
- uses: actions/checkout@v3
6368
- name: Setup Node
@@ -77,7 +82,8 @@ jobs:
7782
fail-fast: false
7883
matrix:
7984
os: [ubuntu-latest, windows-latest, macos-latest]
80-
node-version: [16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
85+
node-version:
86+
[16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
8187
steps:
8288
- uses: actions/checkout@v3
8389
- name: Setup Node
@@ -170,7 +176,7 @@ jobs:
170176
strategy:
171177
fail-fast: false
172178
matrix:
173-
os: [ ubuntu-latest, windows-latest, macos-latest ]
179+
os: [ubuntu-latest, windows-latest, macos-latest]
174180
steps:
175181
- uses: actions/checkout@v3
176182
- name: Setup node from node version file

.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore list
2+
/*
3+
4+
# Do not ignore these folders:
5+
!__tests__/
6+
!.github/
7+
!src/

.prettierrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
printWidth: 80,
3+
tabWidth: 2,
4+
useTabs: false,
5+
semi: true,
6+
singleQuote: true,
7+
trailingComma: 'none',
8+
bracketSpacing: false,
9+
arrowParens: 'avoid'
10+
};

.prettierrc.json

-11
This file was deleted.

__tests__/authutil.test.ts

+20-24
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ describe('authutil tests', () => {
1515
let dbgSpy: jest.SpyInstance;
1616

1717
beforeAll(async () => {
18-
const randPath = path.join(
19-
Math.random()
20-
.toString(36)
21-
.substring(7)
22-
);
18+
const randPath = path.join(Math.random().toString(36).substring(7));
2319
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
2420
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
2521
const tempDir = path.join(_runnerDir, randPath, 'temp');
@@ -67,10 +63,10 @@ describe('authutil tests', () => {
6763
}, 100000);
6864

6965
function readRcFile(rcFile: string) {
70-
let rc = {};
71-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
66+
const rc = {};
67+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
7268
for (const line of contents.split(os.EOL)) {
73-
let parts = line.split('=');
69+
const parts = line.split('=');
7470
if (parts.length == 2) {
7571
rc[parts[0].trim()] = parts[1].trim();
7672
}
@@ -82,8 +78,8 @@ describe('authutil tests', () => {
8278
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
8379

8480
expect(fs.statSync(rcFile)).toBeDefined();
85-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
86-
let rc = readRcFile(rcFile);
81+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
82+
const rc = readRcFile(rcFile);
8783
expect(rc['registry']).toBe('https://registry.npmjs.org/');
8884
expect(rc['always-auth']).toBe('false');
8985
});
@@ -92,7 +88,7 @@ describe('authutil tests', () => {
9288
await auth.configAuthentication('https://registry.npmjs.org', 'false');
9389

9490
expect(fs.statSync(rcFile)).toBeDefined();
95-
let rc = readRcFile(rcFile);
91+
const rc = readRcFile(rcFile);
9692
expect(rc['registry']).toBe('https://registry.npmjs.org/');
9793
expect(rc['always-auth']).toBe('false');
9894
});
@@ -102,7 +98,7 @@ describe('authutil tests', () => {
10298
await auth.configAuthentication('https://registry.npmjs.org', 'false');
10399

104100
expect(fs.statSync(rcFile)).toBeDefined();
105-
let rc = readRcFile(rcFile);
101+
const rc = readRcFile(rcFile);
106102
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
107103
expect(rc['always-auth']).toBe('false');
108104
});
@@ -111,24 +107,24 @@ describe('authutil tests', () => {
111107
await auth.configAuthentication('npm.pkg.github.com', 'false');
112108

113109
expect(fs.statSync(rcFile)).toBeDefined();
114-
let rc = readRcFile(rcFile);
110+
const rc = readRcFile(rcFile);
115111
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
116112
expect(rc['always-auth']).toBe('false');
117113
});
118114

119115
it('Sets up npmrc for always-auth true', async () => {
120116
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
121117
expect(fs.statSync(rcFile)).toBeDefined();
122-
let rc = readRcFile(rcFile);
118+
const rc = readRcFile(rcFile);
123119
expect(rc['registry']).toBe('https://registry.npmjs.org/');
124120
expect(rc['always-auth']).toBe('true');
125121
});
126122

127-
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
123+
it('is already set the NODE_AUTH_TOKEN export it', async () => {
128124
process.env.NODE_AUTH_TOKEN = 'foobar';
129125
await auth.configAuthentication('npm.pkg.github.com', 'false');
130126
expect(fs.statSync(rcFile)).toBeDefined();
131-
let rc = readRcFile(rcFile);
127+
const rc = readRcFile(rcFile);
132128
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
133129
expect(rc['always-auth']).toBe('false');
134130
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
@@ -137,7 +133,7 @@ describe('authutil tests', () => {
137133
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
138134
fs.writeFileSync(rcFile, 'registry=NNN');
139135
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
140-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
136+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
141137
expect(contents).toBe(
142138
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
143139
);
@@ -146,7 +142,7 @@ describe('authutil tests', () => {
146142
it('configAuthentication should overwrite only non-scoped', async () => {
147143
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
148144
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
149-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
145+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
150146
expect(contents).toBe(
151147
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
152148
);
@@ -155,7 +151,7 @@ describe('authutil tests', () => {
155151
it('configAuthentication should add non-scoped to scoped', async () => {
156152
fs.writeFileSync(rcFile, '@myscope:registry=NNN');
157153
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
158-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
154+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
159155
expect(contents).toBe(
160156
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
161157
);
@@ -165,7 +161,7 @@ describe('authutil tests', () => {
165161
process.env['INPUT_SCOPE'] = 'myscope';
166162
fs.writeFileSync(rcFile, `@myscope:registry=NNN`);
167163
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
168-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
164+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
169165
expect(contents).toBe(
170166
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
171167
);
@@ -175,7 +171,7 @@ describe('authutil tests', () => {
175171
process.env['INPUT_SCOPE'] = 'myscope';
176172
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
177173
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
178-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
174+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
179175
expect(contents).toBe(
180176
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
181177
);
@@ -185,7 +181,7 @@ describe('authutil tests', () => {
185181
process.env['INPUT_SCOPE'] = 'myscope';
186182
fs.writeFileSync(rcFile, `registry=MMM`);
187183
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
188-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
184+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
189185
expect(contents).toBe(
190186
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
191187
);
@@ -198,7 +194,7 @@ describe('authutil tests', () => {
198194
`@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM`
199195
);
200196
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
201-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
197+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
202198
expect(contents).toBe(
203199
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
204200
);
@@ -208,7 +204,7 @@ describe('authutil tests', () => {
208204
process.env['INPUT_SCOPE'] = 'myscope';
209205
fs.writeFileSync(rcFile, `@otherscope:registry=MMM`);
210206
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
211-
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
207+
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
212208
expect(contents).toBe(
213209
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
214210
);

__tests__/cache-restore.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('cache-restore', () => {
108108
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
109109
'Throw an error because %s is not supported',
110110
async packageManager => {
111-
await expect(restoreCache(packageManager)).rejects.toThrowError(
111+
await expect(restoreCache(packageManager)).rejects.toThrow(
112112
`Caching for '${packageManager}' is not supported`
113113
);
114114
}

__tests__/cache-save.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('run', () => {
1818
const commonPath = '/some/random/path';
1919
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
2020

21-
let inputs = {} as any;
21+
const inputs = {} as any;
2222

2323
let getInputSpy: jest.SpyInstance;
2424
let infoSpy: jest.SpyInstance;

0 commit comments

Comments
 (0)