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"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@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
}
}
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "github", "jest", "prettier"],
"extends": [
"plugin:github/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
},
"rules": {
"filenames/match-regex": "off",
"github/no-then": "off",
"i18n-text/no-en": "off"
}
}

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": {
"dist/": true,
"lib/": true,
"**/node_modules/": true,
"**/node_modules/": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
}

View File

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

View File

@@ -29,17 +29,20 @@ 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.
Install the dependencies
Install the dependencies
```bash
$ npm install
```
Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```
Run the tests :heavy_check_mark:
Run the tests :heavy_check_mark:
```bash
$ npm test
@@ -64,9 +67,9 @@ import * as core from '@actions/core';
...
async function run() {
try {
try {
...
}
}
catch (error) {
core.setFailed(error.message);
}
@@ -79,9 +82,10 @@ See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/R
## Publish to a distribution branch
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:
```bash
$ npm run package
$ git add dist
@@ -91,7 +95,7 @@ $ git push origin releases/v1
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
Your action is now published! :rocket:
Your action is now published! :rocket:
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

View File

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

View File

@@ -1,4 +1,4 @@
name: Add to Project
name: Add to Project
description: Automatically add issues and PRs to GitHub projects
author: GitHub
inputs:

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

View File

@@ -6,4 +6,4 @@ module.exports = {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
}

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

View File

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

View File

@@ -1,12 +1,12 @@
{
"compilerOptions": {
"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'. */
"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. */
"strict": true, /* Enable all strict type-checking options. */
"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'. */
"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'. */,
"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. */,
"strict": true /* Enable all strict type-checking options. */,
"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'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}