Skip to content

Commit

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

* Update eslint config

* Update eslint config

* Update dependencies

* Update ESLint and Prettier configurations

* update package.json

* Update prettier command

* Update prettier config file

* Change CRLF to LF

* Update docs

* Update docs
  • Loading branch information
IvanZosimov committed Mar 8, 2023
1 parent a3d889c commit 7406d65
Show file tree
Hide file tree
Showing 26 changed files with 2,340 additions and 229 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
@@ -0,0 +1,6 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!src/
49 changes: 49 additions & 0 deletions .eslintrc.js
@@ -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
}
};
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1,2 +1,2 @@
* text=auto
* text=auto eol=lf
.licenses/** -diff linguist-generated=true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
@@ -1 +1 @@
blank_issues_enabled: false
blank_issues_enabled: false
2 changes: 1 addition & 1 deletion .github/workflows/basic-validation.yml
Expand Up @@ -13,4 +13,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
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
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
2 changes: 1 addition & 1 deletion .github/workflows/licensed.yml
Expand Up @@ -11,4 +11,4 @@ on:
jobs:
call-licensed:
name: Licensed
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
6 changes: 3 additions & 3 deletions .github/workflows/versions.yml
Expand Up @@ -42,7 +42,7 @@ jobs:
go-version: oldstable
- name: Verify Go
run: go version

aliases-arch:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -52,8 +52,8 @@ jobs:
version: [stable, oldstable]
architecture: [x64, x32]
exclude:
- os: macos-latest
architecture: x32
- os: macos-latest
architecture: x32
steps:
- uses: actions/checkout@v3
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
@@ -0,0 +1,7 @@
# Ignore list
/*

# Do not ignore these folders:
!__tests__/
!.github/
!src/
10 changes: 10 additions & 0 deletions .prettierrc.js
@@ -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.

18 changes: 9 additions & 9 deletions __tests__/cache-restore.test.ts
Expand Up @@ -8,14 +8,14 @@ import {PackageManagerInfo} from '../src/package-managers';

describe('restoreCache', () => {
//Arrange
let hashFilesSpy = jest.spyOn(glob, 'hashFiles');
let getCacheDirectoryPathSpy = jest.spyOn(
const hashFilesSpy = jest.spyOn(glob, 'hashFiles');
const getCacheDirectoryPathSpy = jest.spyOn(
cacheUtils,
'getCacheDirectoryPath'
);
let restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
let infoSpy = jest.spyOn(core, 'info');
let setOutputSpy = jest.spyOn(core, 'setOutput');
const restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
const infoSpy = jest.spyOn(core, 'info');
const setOutputSpy = jest.spyOn(core, 'setOutput');

const versionSpec = '1.13.1';
const packageManager = 'default';
Expand All @@ -40,13 +40,13 @@ describe('restoreCache', () => {
});

//Act + Assert
expect(async () => {
await expect(async () => {
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
}).rejects.toThrowError(
}).rejects.toThrow(
'Some specified paths were not resolved, unable to cache dependencies.'
);
});
Expand All @@ -71,7 +71,7 @@ describe('restoreCache', () => {
packageManager,
cacheDependencyPath
);
expect(infoSpy).toBeCalledWith(`Cache is not found`);
expect(infoSpy).toHaveBeenCalledWith(`Cache is not found`);
});

it('should set output if cache hit is occured', async () => {
Expand All @@ -94,6 +94,6 @@ describe('restoreCache', () => {
packageManager,
cacheDependencyPath
);
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
});
});
30 changes: 13 additions & 17 deletions __tests__/cache-utils.test.ts
Expand Up @@ -6,7 +6,7 @@ import {PackageManagerInfo} from '../src/package-managers';

describe('getCommandOutput', () => {
//Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');

it('should return trimmed stdout in case of successful exit code', async () => {
//Arrange
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('getCommandOutput', () => {
});

//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCommandOutput('command');
}).rejects.toThrow();
});
Expand All @@ -62,15 +62,15 @@ describe('getPackageManagerInfo', () => {
const packageManagerName = 'invalidName';

//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getPackageManagerInfo(packageManagerName);
}).rejects.toThrow();
});
});

describe('getCacheDirectoryPath', () => {
//Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');

const validPackageManager: PackageManagerInfo = {
dependencyFilePattern: 'go.sum',
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('getCacheDirectoryPath', () => {
});

//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});
Expand All @@ -136,41 +136,39 @@ describe('getCacheDirectoryPath', () => {
});

//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});
});

describe('isCacheFeatureAvailable', () => {
//Arrange
let isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
let warningSpy = jest.spyOn(core, 'warning');
const isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
const warningSpy = jest.spyOn(core, 'warning');

it('should return true when cache feature is available', () => {
//Arrange
isFeatureAvailableSpy.mockImplementation(() => {
return true;
});

let functionResult;

//Act
functionResult = cacheUtils.isCacheFeatureAvailable();
const functionResult = cacheUtils.isCacheFeatureAvailable();

//Assert
expect(functionResult).toBeTruthy();
});

it('should warn when cache feature is unavailable and GHES is not used ', () => {
it('should warn when cache feature is unavailable and GHES is not used', () => {
//Arrange
isFeatureAvailableSpy.mockImplementation(() => {
return false;
});

process.env['GITHUB_SERVER_URL'] = 'https://github.com';

let warningMessage =
const warningMessage =
'The runner was not able to contact the cache service. Caching will be skipped';

//Act
Expand All @@ -188,10 +186,8 @@ describe('isCacheFeatureAvailable', () => {

process.env['GITHUB_SERVER_URL'] = 'https://github.com';

let functionResult;

//Act
functionResult = cacheUtils.isCacheFeatureAvailable();
const functionResult = cacheUtils.isCacheFeatureAvailable();

//Assert
expect(functionResult).toBeFalsy();
Expand All @@ -205,7 +201,7 @@ describe('isCacheFeatureAvailable', () => {

process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';

let warningMessage =
const warningMessage =
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';

//Act + Assert
Expand Down

0 comments on commit 7406d65

Please sign in to comment.