Migrates to eslint (#193)

This commit is contained in:
James Ives 2020-03-06 22:36:56 -05:00 committed by GitHub
parent d25f74597f
commit b2acf87217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1204 additions and 121 deletions

62
.eslintrc.json Normal file
View File

@ -0,0 +1,62 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"globals": {
"fetch": true
},
"rules": {
"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-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@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-object-literal-type-assertion": "error",
"@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-interface": "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",
"no-console": "off"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}

View File

@ -19,12 +19,12 @@ jobs:
build-and-deploy: build-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout 🛎️
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with: with:
persist-credentials: false persist-credentials: false
- name: Build and Deploy - name: Build and Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3 uses: JamesIves/github-pages-deploy-action@releases/v3
with: with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
@ -56,7 +56,7 @@ import run, {
init, init,
deploy, deploy,
generateBranch, generateBranch,
actionInterface ActionInterface
} from "github-pages-deploy-action"; } from "github-pages-deploy-action";
``` ```
@ -134,7 +134,7 @@ With this configured you must add the `ssh-agent` step to your workflow and set
with: with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }} ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Build and Deploy - name: Build and Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3 uses: JamesIves/github-pages-deploy-action@releases/v3
with: with:
SSH: true SSH: true
@ -155,7 +155,7 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout 🛎️
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
persist-credentials: false persist-credentials: false
@ -165,12 +165,12 @@ jobs:
npm install npm install
npm run-script build npm run-script build
- name: Install SSH Client - name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.2.0 # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace. uses: webfactory/ssh-agent@v0.2.0 # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace.
with: with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }} ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Build and Deploy Repo - name: Build and Deploy Repo 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3-test uses: JamesIves/github-pages-deploy-action@releases/v3-test
with: with:
BASE_BRANCH: master BASE_BRANCH: master
@ -207,7 +207,7 @@ jobs:
build: build:
runs-on: windows-latest # The first job utilizes windows-latest runs-on: windows-latest # The first job utilizes windows-latest
steps: steps:
- name: Checkout - name: Checkout 🛎️
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
persist-credentials: false persist-credentials: false
@ -227,7 +227,7 @@ jobs:
needs: [build] # The second job must depend on the first one to complete before running, and uses ubuntu-latest instead of windows. needs: [build] # The second job must depend on the first one to complete before running, and uses ubuntu-latest instead of windows.
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout 🛎️
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
persist-credentials: false persist-credentials: false
@ -237,7 +237,7 @@ jobs:
with: with:
name: site name: site
- name: Build and Deploy - name: Build and Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3 uses: JamesIves/github-pages-deploy-action@releases/v3
with: with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}

View File

@ -9,7 +9,7 @@
"scripts": { "scripts": {
"build": "rm -rf lib && tsc --declaration", "build": "rm -rf lib && tsc --declaration",
"test": "jest", "test": "jest",
"lint": "tslint -p tsconfig.json --project '.' || (echo Project needs formatting)", "lint": "eslint src/**/*.ts",
"format": "prettier --write './**/*.ts'" "format": "prettier --write './**/*.ts'"
}, },
"repository": { "repository": {
@ -44,7 +44,9 @@
"jest-circus": "^25.1.0", "jest-circus": "^25.1.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"ts-jest": "^25.0.0", "ts-jest": "^25.0.0",
"tslint": "^6.0.0", "eslint": "^5.16.0",
"eslint-plugin-github": "^2.0.0",
"eslint-plugin-jest": "^22.21.0",
"typescript": "^3.7.4" "typescript": "^3.7.4"
} }
} }

View File

@ -5,7 +5,7 @@ import {isNullOrUndefined} from './util'
const {pusher, repository} = github.context.payload const {pusher, repository} = github.context.payload
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */ /* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
export interface actionInterface { export interface ActionInterface {
/** Deployment access token. */ /** Deployment access token. */
accessToken?: string | null accessToken?: string | null
/** The base branch that the deploy should be made from. */ /** The base branch that the deploy should be made from. */
@ -15,7 +15,7 @@ export interface actionInterface {
/** If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true. */ /** If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true. */
clean?: string | boolean clean?: string | boolean
/** If you need to use CLEAN but you'd like to preserve certain files or folders you can use this option. */ /** If you need to use CLEAN but you'd like to preserve certain files or folders you can use this option. */
cleanExclude?: string | Array<string> cleanExclude?: string | string[]
/** If you need to customize the commit message for an integration you can do so. */ /** If you need to customize the commit message for an integration you can do so. */
commitMessage?: string commitMessage?: string
/** Unhides the Git commands from the function terminal. */ /** Unhides the Git commands from the function terminal. */
@ -49,7 +49,7 @@ export interface actionInterface {
} }
/* Required action data that gets initialized when running within the GitHub Actions environment. */ /* Required action data that gets initialized when running within the GitHub Actions environment. */
export const action: actionInterface = { export const action: ActionInterface = {
accessToken: getInput('ACCESS_TOKEN'), accessToken: getInput('ACCESS_TOKEN'),
baseBranch: getInput('BASE_BRANCH'), baseBranch: getInput('BASE_BRANCH'),
folder: getInput('FOLDER'), folder: getInput('FOLDER'),

View File

@ -23,6 +23,6 @@ export async function execute(cmd: string, cwd: string): Promise<any> {
return Promise.resolve(output) return Promise.resolve(output)
} }
export function stdout(data: any) { export function stdout(data: any): string | void {
output += data.toString().trim() output += data.toString().trim()
} }

View File

@ -1,4 +1,4 @@
import {actionInterface} from './constants' import {ActionInterface} from './constants'
import {execute} from './execute' import {execute} from './execute'
import { import {
hasRequiredParameters, hasRequiredParameters,
@ -7,7 +7,7 @@ import {
} from './util' } from './util'
/* Initializes git in the workspace. */ /* Initializes git in the workspace. */
export async function init(action: actionInterface): Promise<void | Error> { export async function init(action: ActionInterface): Promise<void | Error> {
try { try {
hasRequiredParameters(action) hasRequiredParameters(action)
@ -37,7 +37,7 @@ export async function init(action: actionInterface): Promise<void | Error> {
/* Switches to the base branch. */ /* Switches to the base branch. */
export async function switchToBaseBranch( export async function switchToBaseBranch(
action: actionInterface action: ActionInterface
): Promise<void> { ): Promise<void> {
try { try {
hasRequiredParameters(action) hasRequiredParameters(action)
@ -59,7 +59,7 @@ export async function switchToBaseBranch(
} }
/* Generates the branch if it doesn't exist on the remote. */ /* Generates the branch if it doesn't exist on the remote. */
export async function generateBranch(action: actionInterface): Promise<void> { export async function generateBranch(action: ActionInterface): Promise<void> {
try { try {
hasRequiredParameters(action) hasRequiredParameters(action)
@ -90,7 +90,7 @@ export async function generateBranch(action: actionInterface): Promise<void> {
} }
/* Runs the necessary steps to make the deployment. */ /* Runs the necessary steps to make the deployment. */
export async function deploy(action: actionInterface): Promise<void> { export async function deploy(action: ActionInterface): Promise<void> {
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder' const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch' const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
console.log('Starting to commit changes...') console.log('Starting to commit changes...')
@ -127,9 +127,10 @@ export async function deploy(action: actionInterface): Promise<void> {
typeof action.cleanExclude === 'string' typeof action.cleanExclude === 'string'
? JSON.parse(action.cleanExclude) ? JSON.parse(action.cleanExclude)
: action.cleanExclude : action.cleanExclude
excludedItems.forEach(
(item: string) => (excludes += `--exclude ${item} `) for (const item of excludedItems) {
) excludes += `--exclude ${item} `
}
} catch { } catch {
console.log( console.log(
'There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌' 'There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌'

View File

@ -1,13 +1,13 @@
import {exportVariable, setFailed} from '@actions/core' import {exportVariable, setFailed} from '@actions/core'
import {action, actionInterface} from './constants' import {action, ActionInterface} from './constants'
import {deploy, generateBranch, init} from './git' import {deploy, generateBranch, init} from './git'
import {generateRepositoryPath, generateTokenType} from './util' import {generateRepositoryPath, generateTokenType} from './util'
/** Initializes and runs the action. */ /** Initializes and runs the action. */
export default async function run( export default async function run(
configuration: actionInterface configuration: ActionInterface
): Promise<void> { ): Promise<void> {
let errorState: boolean = false let errorState = false
try { try {
console.log('Checking configuration and starting deployment...🚦') console.log('Checking configuration and starting deployment...🚦')
@ -42,4 +42,4 @@ export default async function run(
} }
} }
export {init, deploy, generateBranch, actionInterface} export {init, deploy, generateBranch, ActionInterface}

View File

@ -1,12 +1,12 @@
import {getInput} from '@actions/core' import {getInput} from '@actions/core'
import {actionInterface} from './constants' import {ActionInterface} from './constants'
/* Utility function that checks to see if a value is undefined or not. */ /* Utility function that checks to see if a value is undefined or not. */
export const isNullOrUndefined = (value: any): boolean => export const isNullOrUndefined = (value: any): boolean =>
typeof value === 'undefined' || value === null || value === '' typeof value === 'undefined' || value === null || value === ''
/* Generates a token type used for the action. */ /* Generates a token type used for the action. */
export const generateTokenType = (action: actionInterface): string => export const generateTokenType = (action: ActionInterface): string =>
action.ssh action.ssh
? 'SSH Deploy Key' ? 'SSH Deploy Key'
: action.accessToken : action.accessToken
@ -16,7 +16,7 @@ export const generateTokenType = (action: actionInterface): string =>
: '...' : '...'
/* Generates a the repository path used to make the commits. */ /* Generates a the repository path used to make the commits. */
export const generateRepositoryPath = (action: actionInterface): string => export const generateRepositoryPath = (action: ActionInterface): string =>
action.ssh action.ssh
? `git@github.com:${action.repositoryName}` ? `git@github.com:${action.repositoryName}`
: `https://${action.accessToken || : `https://${action.accessToken ||
@ -25,7 +25,7 @@ export const generateRepositoryPath = (action: actionInterface): string =>
}.git` }.git`
/* Checks for the required tokens and formatting. Throws an error if any case is matched. */ /* Checks for the required tokens and formatting. Throws an error if any case is matched. */
export const hasRequiredParameters = (action: actionInterface): void => { export const hasRequiredParameters = (action: ActionInterface): void => {
if ( if (
(isNullOrUndefined(action.accessToken) && (isNullOrUndefined(action.accessToken) &&
isNullOrUndefined(action.gitHubToken) && isNullOrUndefined(action.gitHubToken) &&
@ -55,8 +55,8 @@ export const hasRequiredParameters = (action: actionInterface): void => {
/* Suppresses sensitive information from being exposed in error messages. */ /* Suppresses sensitive information from being exposed in error messages. */
export const suppressSensitiveInformation = ( export const suppressSensitiveInformation = (
str: string, str: string,
action: actionInterface action: ActionInterface
) => { ): string => {
let value = str let value = str
if (getInput('DEBUG')) { if (getInput('DEBUG')) {

View File

@ -1,37 +0,0 @@
{
"rules": {
"adjacent-overload-signatures": true,
"ban-comma-operator": true,
"no-namespace": true,
"no-parameter-reassignment": true,
"no-reference": true,
"no-unnecessary-type-assertion": true,
"label-position": true,
"no-conditional-assignment": true,
"no-construct": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": [true, "check-parameters"],
"no-shadowed-variable": true,
"no-empty": [true, "allow-empty-catch"],
"no-floating-promises": false,
"no-implicit-dependencies": true,
"no-invalid-this": true,
"no-string-throw": true,
"no-unsafe-finally": true,
"no-use-before-declare": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
"no-duplicate-imports": true,
"no-empty-interface": {"severity": "warning"},
"no-import-side-effect": {"severity": "warning"},
"no-var-keyword": {"severity": "warning"},
"triple-equals": {"severity": "warning"},
"deprecation": {"severity": "warning"},
"prefer-for-of": {"severity": "warning"},
"unified-signatures": {"severity": "warning"},
"prefer-const": {"severity": "warning"},
"trailing-comma": {"severity": "warning"}
},
"defaultSeverity": "error"
}

1155
yarn.lock

File diff suppressed because it is too large Load Diff