Skip to content

Commit

Permalink
Merge pull request #420 from shogo82148/fix-eslint-warnings
Browse files Browse the repository at this point in the history
fix eslint warnings
  • Loading branch information
shogo82148 authored Nov 10, 2021
2 parents d3a4c1c + e71aed1 commit 373bb47
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 54 deletions.
56 changes: 35 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"plugins": [
"jest",
"@typescript-eslint"
],
"extends": [
"plugin:github/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
},
"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/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",
"@typescript-eslint/ban-ts-comment": "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/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-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-floating-promises": "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"
},
"env": {
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
}
25 changes: 25 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: reviewdog
on: [pull_request]
jobs:

eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: "12"
cache: 'npm'
- run: npm ci
- uses: reviewdog/action-eslint@v1
with:
reporter: github-pr-review
level: warning
eslint_flags: "src/**/*.ts"

actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-actionlint@v1
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ async function run(): Promise<void> {
}
}

run();
void run();
64 changes: 32 additions & 32 deletions src/upload-release-asset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as fs from "fs";
import * as stream from "stream";
import * as path from "path";
import * as url from "url";
import * as core from "@actions/core";
import * as fs from "fs";
import * as glob from "@actions/glob";
import * as http from "@actions/http-client";
import * as mime from "mime-types";
import * as path from "path";
import * as stream from "stream";
import * as url from "url";

interface Options {
githubToken: string;
Expand Down Expand Up @@ -122,10 +122,10 @@ const getRelease = async (
params: ReposGetReleaseParams
): Promise<Response<ReposGetReleaseResponse>> => {
const client = newGitHubClient(params.githubToken);
const url = `${getApiBaseUrl()}/repos/${params.owner}/${params.repo}/releases/${
const apiUrl = `${getApiBaseUrl()}/repos/${params.owner}/${params.repo}/releases/${
params.releaseId
}`;
const resp = await client.request("GET", url, "", {});
const resp = await client.request("GET", apiUrl, "", {});
const statusCode = resp.message.statusCode;
const contents = await resp.readBody();
if (statusCode !== 200) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export async function upload(opts: Options): Promise<Outputs> {
"content-type": content_type,
"content-length": stat.size,
},
name: name,
name,
data: fs.createReadStream(file),
});
core.debug(JSON.stringify(response));
Expand All @@ -180,7 +180,7 @@ async function fsStats(file: string): Promise<fs.Stats> {
});
}

async function validateFilenames(files: string[], opts: Options) {
async function validateFilenames(files: string[], opts: Options): Promise<void> {
if (files.length > 1 && opts.assetName !== "") {
throw new Error("validation error: cannot upload multiple files with asset_name option");
}
Expand All @@ -201,20 +201,20 @@ async function validateFilenames(files: string[], opts: Options) {
releaseId,
githubToken: opts.githubToken,
});
release.data.assets.forEach((asset) => {
for (const asset of release.data.assets) {
assets[asset.name] = {
name: asset.name,
asset: asset,
asset,
files: [],
};
});
}

// check duplications
const duplications: AssetOrFile[] = [];
files.forEach((file) => {
for (const file of files) {
const name = canonicalName(opts.assetName || path.basename(file));
const asset = assets[name];
if (asset) {
if (name in assets) {
const asset = assets[name];
duplications.push(asset);
asset.files.push(file);
} else {
Expand All @@ -223,31 +223,31 @@ async function validateFilenames(files: string[], opts: Options) {
files: [file],
};
}
});
}

// report the result of validation
let errorCount = 0;
duplications.forEach((item) => {
if (item.files.length <= 1) {
return;
for (const item of duplications) {
if (item.files.length > 1) {
core.error(
`validation error: file name "${item.name}" is duplicated. (${item.files.join(", ")})`
);
errorCount++;
}
core.error(
`validation error: file name "${item.name}" is duplicated. (${item.files.join(", ")})`
);
errorCount++;
});
}

// report the result of validation
const deleteAssets = duplications
.filter((item) => {
return item.files.length === 1 && item.asset;
})
.map((item) => item.asset!);
const deleteAssets: ReposGetReleaseAsset[] = [];
for (const item of duplications) {
if (item.files.length === 1 && item.asset) {
deleteAssets.push(item.asset);
}
}
if (!opts.overwrite) {
deleteAssets.forEach((item) => {
for (const item of deleteAssets) {
core.error(`validation error: file name "${item.name}" already exists`);
errorCount++;
});
}
}
if (errorCount > 0) {
throw new Error("validation error");
Expand Down Expand Up @@ -279,10 +279,10 @@ export function canonicalName(name: string): string {
name = name.replace(/[^-+@_.a-zA-Z0-9]/g, "");
name = name.replace(/[.]+/g, ".");
if (name.match(/^[.].+$/)) {
return "default" + name.replace(/[.]$/, "");
return `default${name.replace(/[.]$/, "")}`;
}
if (name.match(/^[^.]+[.]$/)) {
return "default." + name.replace(/[.]$/, "");
return `default.${name.replace(/[.]$/, "")}`;
}
return name.replace(/[.]$/, "");
}
Expand Down

0 comments on commit 373bb47

Please sign in to comment.