Skip to content

Commit

Permalink
Add and configure ESLint and update configuration for Prettier (#703)
Browse files Browse the repository at this point in the history
* Add ESLinter and update Prettier

* Update eslint config

* Update dependencies

* Rebuild action

* Update package.json

* Updates docs

* Update docs
  • Loading branch information
IvanZosimov authored Mar 8, 2023
1 parent 7c29869 commit 962678f
Show file tree
Hide file tree
Showing 31 changed files with 3,949 additions and 1,690 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!src/
49 changes: 49 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:eslint-plugin-jest/recommended',
'eslint-config-prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-jest'],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description'
}
],
'no-console': 'error',
'yoda': 'error',
'prefer-const': [
'error',
{
destructuring: 'all'
}
],
'no-control-regex': 'off',
'no-constant-condition': ['error', {checkLoops: false}]
},
overrides: [
{
files: ['**/*{test,spec}.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'jest/no-standalone-expect': 'off',
'jest/no-conditional-expect': 'off',
'no-console': 'off',

}
}
],
env: {
node: true,
es6: true,
'jest/globals': true
}
};
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
.licenses/** -diff linguist-generated=true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blank_issues_enabled: false
blank_issues_enabled: false
2 changes: 1 addition & 1 deletion .github/workflows/basic-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ on:
jobs:
call-basic-validation:
name: Basic validation
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ on:
jobs:
call-check-dist:
name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: CodeQL analysis

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
schedule:
- cron: '0 3 * * 0'

jobs:
call-codeQL-analysis:
name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
10 changes: 5 additions & 5 deletions .github/workflows/release-new-action-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
name: releaseNewActionVersion
runs-on: ubuntu-latest
steps:
- name: Update the ${{ env.TAG_NAME }} tag
uses: actions/[email protected]
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
- name: Update the ${{ env.TAG_NAME }} tag
uses: actions/[email protected]
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
12 changes: 9 additions & 3 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: ['20-v8-canary', '20.0.0-v8-canary','20.0.0-v8-canary20221103f7e2421e91']
node-version:
[
'20-v8-canary',
'20.0.0-v8-canary',
'20.0.0-v8-canary20221103f7e2421e91'
]
steps:
- uses: actions/checkout@v3
- name: Setup Node
Expand All @@ -77,7 +82,8 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
node-version:
[16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
steps:
- uses: actions/checkout@v3
- name: Setup Node
Expand Down Expand Up @@ -170,7 +176,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup node from node version file
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!.github/
!src/
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: false,
arrowParens: 'avoid'
};
11 changes: 0 additions & 11 deletions .prettierrc.json

This file was deleted.

44 changes: 20 additions & 24 deletions __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ describe('authutil tests', () => {
let dbgSpy: jest.SpyInstance;

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

function readRcFile(rcFile: string) {
let rc = {};
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const rc = {};
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
for (const line of contents.split(os.EOL)) {
let parts = line.split('=');
const parts = line.split('=');
if (parts.length == 2) {
rc[parts[0].trim()] = parts[1].trim();
}
Expand All @@ -82,8 +78,8 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'false');

expect(fs.statSync(rcFile)).toBeDefined();
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
let rc = readRcFile(rcFile);
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
});
Expand All @@ -92,7 +88,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org', 'false');

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

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

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

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

it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
it('is already set the NODE_AUTH_TOKEN export it', async () => {
process.env.NODE_AUTH_TOKEN = 'foobar';
await auth.configAuthentication('npm.pkg.github.com', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
let rc = readRcFile(rcFile);
const rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
Expand All @@ -137,7 +133,7 @@ describe('authutil tests', () => {
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
fs.writeFileSync(rcFile, 'registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -146,7 +142,7 @@ describe('authutil tests', () => {
it('configAuthentication should overwrite only non-scoped', async () => {
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -155,7 +151,7 @@ describe('authutil tests', () => {
it('configAuthentication should add non-scoped to scoped', async () => {
fs.writeFileSync(rcFile, '@myscope:registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -165,7 +161,7 @@ describe('authutil tests', () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@myscope:registry=NNN`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -175,7 +171,7 @@ describe('authutil tests', () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -185,7 +181,7 @@ describe('authutil tests', () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
Expand All @@ -198,7 +194,7 @@ describe('authutil tests', () => {
`@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM`
);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@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`
);
Expand All @@ -208,7 +204,7 @@ describe('authutil tests', () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@otherscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@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`
);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('cache-restore', () => {
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
'Throw an error because %s is not supported',
async packageManager => {
await expect(restoreCache(packageManager)).rejects.toThrowError(
await expect(restoreCache(packageManager)).rejects.toThrow(
`Caching for '${packageManager}' is not supported`
);
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cache-save.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('run', () => {
const commonPath = '/some/random/path';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');

let inputs = {} as any;
const inputs = {} as any;

let getInputSpy: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
Expand Down
Loading

1 comment on commit 962678f

@huanban
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qqqqqq

Please sign in to comment.