Improve linting

This commit is contained in:
Jonathan Clem
2022-01-31 15:38:31 -05:00
parent 609b064e53
commit b4c121a252
15 changed files with 1980 additions and 9370 deletions

View File

@@ -1,55 +1,25 @@
{ {
"plugins": ["jest", "@typescript-eslint"], "root": true,
"extends": ["plugin:github/recommended"], "parser": "@typescript-eslint/parser",
"parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint", "github", "jest", "prettier"],
"parserOptions": { "extends": [
"ecmaVersion": 9, "plugin:github/recommended",
"sourceType": "module", "plugin:@typescript-eslint/eslint-recommended",
"project": "./tsconfig.json" "plugin:@typescript-eslint/recommended",
}, "prettier"
"rules": { ],
"i18n-text/no-en": "off", "parserOptions": {
"eslint-comments/no-use": "off", "ecmaVersion": 2019,
"import/no-namespace": "off", "sourceType": "module"
"no-unused-vars": "off", },
"@typescript-eslint/no-unused-vars": "error", "env": {
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}], "node": true,
"@typescript-eslint/no-require-imports": "error", "es6": true,
"@typescript-eslint/array-type": "error", "jest/globals": true
"@typescript-eslint/await-thenable": "error", },
"@typescript-eslint/ban-ts-comment": "error", "rules": {
"camelcase": "off", "filenames/match-regex": "off",
"@typescript-eslint/consistent-type-assertions": "error", "github/no-then": "off",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}], "i18n-text/no-en": "off"
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
} }
}

View File

@@ -1,9 +0,0 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}

View File

@@ -1,8 +1,12 @@
{ {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": true,
"files.exclude": { "files.exclude": {
"dist/": true, "dist/": true,
"lib/": true, "lib/": true,
"**/node_modules/": true, "**/node_modules/": true
}, },
"typescript.tsdk": "node_modules/typescript/lib" "typescript.tsdk": "node_modules/typescript/lib"
} }

View File

@@ -1 +0,0 @@
* @actions/actions-runtime

View File

@@ -30,16 +30,19 @@ adding repo issues to the project).
> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance. > First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
Install the dependencies Install the dependencies
```bash ```bash
$ npm install $ npm install
``` ```
Build the typescript and package it for distribution Build the typescript and package it for distribution
```bash ```bash
$ npm run build && npm run package $ npm run build && npm run package
``` ```
Run the tests :heavy_check_mark: Run the tests :heavy_check_mark:
```bash ```bash
$ npm test $ npm test
@@ -82,6 +85,7 @@ See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/R
Actions are run from GitHub repos so we will checkin the packed dist folder. Actions are run from GitHub repos so we will checkin the packed dist folder.
Then run [ncc](https://github.com/zeit/ncc) and push the results: Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash ```bash
$ npm run package $ npm run package
$ git add dist $ git add dist

View File

@@ -1,4 +1,4 @@
import { expect, test } from '@jest/globals' import {expect, test} from '@jest/globals'
test('sanity check', () => { test('sanity check', () => {
expect(true).toBeTruthy() expect(true).toBeTruthy()

159
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

2
dist/sourcemap-register.js generated vendored

File diff suppressed because one or more lines are too long

10952
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,44 +1,55 @@
{ {
"name": "@actions/add-to-project", "name": "@actions/add-to-project",
"version": "0.0.0",
"private": true,
"description": "Automatically issues and PRs to GitHub projects", "description": "Automatically issues and PRs to GitHub projects",
"main": "lib/main.js", "version": "0.0.0",
"scripts": { "author": "GitHub and contributors",
"build": "tsc", "dependencies": {
"format": "prettier --write '**/*.ts'", "@actions/core": "^1.6.0",
"format-check": "prettier --check '**/*.ts'", "@actions/github": "^5.0.0"
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
}, },
"repository": { "engines": {
"type": "git", "node": ">=10.0.0 <17.0.0",
"url": "git+https://github.com/actions/typescript-action.git" "npm": ">= 7.0.0"
},
"devDependencies": {
"@github/prettier-config": "^0.0.4",
"@types/node": "^12.12.6",
"@typescript-eslint/parser": "^5.10.2",
"@vercel/ncc": "^0.33.1",
"concurrently": "^7.0.0",
"eslint": "^8.8.0",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.7",
"prettier": "2.5.1",
"ts-jest": "^27.1.3",
"typescript": "^4.5.5"
}, },
"keywords": [ "keywords": [
"actions", "actions",
"node", "node",
"setup" "setup"
], ],
"author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "main": "lib/main.js",
"@actions/core": "^1.6.0", "prettier": "@github/prettier-config",
"@actions/github": "^5.0.0" "private": true,
"repository": {
"type": "git",
"url": "git+https://github.com/actions/add-to-project.git"
}, },
"devDependencies": { "scripts": {
"@types/node": "^16.10.5", "build": "npm run fix:format && npm run check && npm run build:compile && npm run build:package",
"@typescript-eslint/parser": "^5.8.1", "build:compile": "tsc",
"@vercel/ncc": "^0.31.1", "build:package": "ncc build --source-map --license licenses.txt",
"eslint": "^7.32.0", "check": "concurrently -n check: -c red,green,blue -g npm:check:*",
"eslint-plugin-github": "^4.3.2", "check:build": "tsc --noEmit",
"eslint-plugin-jest": "^25.3.2", "check:format": "prettier --check .",
"jest": "^27.2.5", "check:lint": "eslint .",
"js-yaml": "^4.1.0", "fix:format": "prettier --write .",
"prettier": "2.5.1", "lint": "eslint src/**/*.ts",
"ts-jest": "^27.1.2", "package": "ncc build --source-map --license licenses.txt",
"typescript": "^4.4.4" "test": "jest"
} }
} }

View File

@@ -1,7 +1,5 @@
/* eslint-disable github/no-then */ import core from '@actions/core'
import github from '@actions/github'
import * as core from '@actions/core'
import * as github from '@actions/github'
// TODO: Ensure this (and the Octokit client) works for non-github.com URLs, as well. // TODO: Ensure this (and the Octokit client) works for non-github.com URLs, as well.
// https://github.com/orgs|users/<ownerName>/projects/<projectNumber> // https://github.com/orgs|users/<ownerName>/projects/<projectNumber>
@@ -36,22 +34,15 @@ async function run(): Promise<void> {
const labeled = core.getInput('labeled')?.split(',') ?? [] const labeled = core.getInput('labeled')?.split(',') ?? []
const octokit = github.getOctokit(ghToken) const octokit = github.getOctokit(ghToken)
const urlMatch = projectUrl.match(urlParse) const urlMatch = projectUrl.match(urlParse)
const issue = const issue = github.context.payload.issue ?? github.context.payload.pull_request
github.context.payload.issue ?? github.context.payload.pull_request const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name)
const issueLabels: string[] = (issue?.labels ?? []).map(
(l: {name: string}) => l.name
)
// Ensure the issue matches our `labeled` filter, if provided. // Ensure the issue matches our `labeled` filter, if provided.
if (labeled.length > 0) { if (labeled.length > 0) {
const hasLabel = issueLabels.some(l => labeled.includes(l)) const hasLabel = issueLabels.some(l => labeled.includes(l))
if (!hasLabel) { if (!hasLabel) {
core.info( core.info(`Skipping issue ${issue?.number} because it does not have one of the labels: ${labeled.join(', ')}`)
`Skipping issue ${
issue?.number
} because it does not have one of the labels: ${labeled.join(', ')}`
)
return return
} }
@@ -125,17 +116,10 @@ run()
}) })
function mustGetOwnerTypeQuery(ownerType?: string): 'organization' | 'user' { function mustGetOwnerTypeQuery(ownerType?: string): 'organization' | 'user' {
const ownerTypeQuery = const ownerTypeQuery = ownerType === 'orgs' ? 'organization' : ownerType === 'users' ? 'user' : null
ownerType === 'orgs'
? 'organization'
: ownerType === 'users'
? 'user'
: null
if (!ownerTypeQuery) { if (!ownerTypeQuery) {
throw new Error( throw new Error(`Unsupported ownerType: ${ownerType}. Must be one of 'orgs' or 'users'`)
`Unsupported ownerType: ${ownerType}. Must be one of 'orgs' or 'users'`
)
} }
return ownerTypeQuery return ownerTypeQuery

View File

@@ -1,12 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib", /* Redirect output structure to the directory. */ "outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true, /* Enable all strict type-checking options. */ "strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}, },
"exclude": ["node_modules", "**/*.test.ts"] "exclude": ["node_modules", "**/*.test.ts"]
} }