Add and configure ESLint and update configuration for Prettier (#508)

* Add ESLint and update Prettier

* Rebuild action

* Update package.json
This commit is contained in:
Ivan
2023-03-09 15:02:17 +02:00
committed by GitHub
parent ba790c862c
commit 8d81f881dd
17 changed files with 2242 additions and 35 deletions

7
.eslintignore Normal file
View File

@@ -0,0 +1,7 @@
# Ignore list
/*
# Do not ignore these folders:
!__tests__/
!__mocks__/
!src/

49
.eslintrc.js Normal file
View File

@@ -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
.gitattributes vendored
View File

@@ -1,4 +1,4 @@
* text=auto * text=auto eol=lf
.licenses/** -diff linguist-generated=true .licenses/** -diff linguist-generated=true
# don't diff machine generated files # don't diff machine generated files

View File

@@ -1 +1 @@
blank_issues_enabled: false blank_issues_enabled: false

View File

@@ -14,4 +14,4 @@ on:
jobs: jobs:
call-basic-validation: call-basic-validation:
name: 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

View File

@@ -14,4 +14,4 @@ on:
jobs: jobs:
call-check-dist: call-check-dist:
name: 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

View File

@@ -2,13 +2,13 @@ name: CodeQL analysis
on: on:
push: push:
branches: [ main ] branches: [main]
pull_request: pull_request:
branches: [ main ] branches: [main]
schedule: schedule:
- cron: '0 3 * * 0' - cron: '0 3 * * 0'
jobs: jobs:
call-codeQL-analysis: call-codeQL-analysis:
name: CodeQL analysis name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main

View File

@@ -12,4 +12,4 @@ on:
jobs: jobs:
call-licensed: call-licensed:
name: Licensed name: Licensed
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main uses: actions/reusable-workflows/.github/workflows/licensed.yml@main

View File

@@ -21,8 +21,8 @@ jobs:
name: releaseNewActionVersion name: releaseNewActionVersion
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Update the ${{ env.TAG_NAME }} tag - name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@v0.2.2 uses: actions/publish-action@v0.2.2
with: with:
source-tag: ${{ env.TAG_NAME }} source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }} slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

8
.prettierignore Normal file
View File

@@ -0,0 +1,8 @@
# Ignore list
/*
# Do not ignore these folders:
!__tests__/
!__mocks__/
!.github/
!src/

10
.prettierrc.js Normal file
View File

@@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: false,
arrowParens: 'avoid'
};

View File

@@ -1,12 +0,0 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript",
"endOfLine": "auto"
}

View File

@@ -48,7 +48,7 @@ describe('run', () => {
}); });
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => { it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = { const mockInput = {
'repo-token': 'foo', 'repo-token': 'foo',
'configuration-path': 'bar', 'configuration-path': 'bar',
'sync-labels': true 'sync-labels': true
@@ -79,7 +79,7 @@ describe('run', () => {
}); });
it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => { it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = { const mockInput = {
'repo-token': 'foo', 'repo-token': 'foo',
'configuration-path': 'bar', 'configuration-path': 'bar',
'sync-labels': false 'sync-labels': false

2
dist/index.js vendored
View File

@@ -52,7 +52,7 @@ function run() {
const syncLabels = !!core.getInput('sync-labels', { required: false }); const syncLabels = !!core.getInput('sync-labels', { required: false });
const prNumber = getPrNumber(); const prNumber = getPrNumber();
if (!prNumber) { if (!prNumber) {
console.log('Could not get pull request number from context, exiting'); core.info('Could not get pull request number from context, exiting');
return; return;
} }
const client = github.getOctokit(token); const client = github.getOctokit(token);

2139
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,9 +5,10 @@
"main": "lib/main.js", "main": "lib/main.js",
"scripts": { "scripts": {
"build": "tsc && ncc build lib/main.js", "build": "tsc && ncc build lib/main.js",
"format": "prettier --write **/*.ts", "format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write **/*.{ts,yml,yaml}",
"format-check": "prettier --check **/*.ts", "format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check **/*.{ts,yml,yaml}",
"lint": "echo \"Fake command that does nothing. It is used in reusable workflows\"", "lint": "eslint --config ./.eslintrc.js **/*.ts",
"lint:fix": "eslint --config ./.eslintrc.js **/*.ts --fix",
"test": "jest" "test": "jest"
}, },
"repository": { "repository": {
@@ -30,10 +31,15 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.4.1", "@types/jest": "^27.4.1",
"@types/node": "^16.11.7",
"@types/minimatch": "^5.1.2",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"@types/minimatch": "^5.1.2",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^27.5.1", "jest": "^27.5.1",
"prettier": "^2.8.4", "prettier": "^2.8.4",
"ts-jest": "^27.1.3", "ts-jest": "^27.1.3",

View File

@@ -19,7 +19,7 @@ export async function run() {
const prNumber = getPrNumber(); const prNumber = getPrNumber();
if (!prNumber) { if (!prNumber) {
console.log('Could not get pull request number from context, exiting'); core.info('Could not get pull request number from context, exiting');
return; return;
} }