Skip to content

Commit

Permalink
Update the settings of the static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 29, 2024
1 parent df6f2ce commit 6f9ddb0
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 18 deletions.
13 changes: 9 additions & 4 deletions etc/eslint.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ module.exports = {
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended-type-checked"
],
overrides: [
{
files: ["*.cjs", "*.js", "*.mjs"],
files: ["*.{cjs,js,mjs}"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off"
}
},
{
files: ["test/**/*.js"],
rules: {"@typescript-eslint/no-floating-promises": "off"}
}
],
parser: "@typescript-eslint/parser",
Expand Down Expand Up @@ -135,7 +139,7 @@ module.exports = {
"no-useless-rename": "error",
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-void": ["error", {allowAsStatement: true}],
"no-warning-comments": "warn",
"object-shorthand": "error",
"one-var": ["error", "never"],
Expand Down Expand Up @@ -190,7 +194,7 @@ module.exports = {
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-array-delete": "error",
"@typescript-eslint/no-confusing-non-null-assertion": "error",
"@typescript-eslint/no-confusing-void-expression": ["error", {ignoreArrowShorthand: true}],
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"@typescript-eslint/no-dynamic-delete": "error",
"@typescript-eslint/no-empty-function": "error",
Expand Down Expand Up @@ -243,6 +247,7 @@ module.exports = {
"@typescript-eslint/prefer-ts-expect-error": "error",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/return-await": "error",
"@typescript-eslint/sort-type-constituents": "error",
"@typescript-eslint/strict-boolean-expressions": "off",
Expand Down
3 changes: 2 additions & 1 deletion example/check_comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ try {
console.log(result == CheckResult.ham ? "The comment is ham." : "The comment is spam.");
}
catch (error) {
console.log(`An error occurred: ${error}`);
const message = error instanceof Error ? error.message : String(error);
console.log(`An error occurred: ${message}`);
}
3 changes: 2 additions & 1 deletion example/submit_ham.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ try {
console.log("The comment was successfully submitted as ham.");
}
catch (error) {
console.log(`An error occurred: ${error}`);
const message = error instanceof Error ? error.message : String(error);
console.log(`An error occurred: ${message}`);
}
3 changes: 2 additions & 1 deletion example/submit_spam.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ try {
console.log("The comment was successfully submitted as spam.");
}
catch (error) {
console.log(`An error occurred: ${error}`);
const message = error instanceof Error ? error.message : String(error);
console.log(`An error occurred: ${message}`);
}
3 changes: 2 additions & 1 deletion example/verify_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ try {
console.log(isValid ? "The API key is valid." : "The API key is invalid.");
}
catch (error) {
console.log(`An error occurred: ${error}`);
const message = error instanceof Error ? error.message : String(error);
console.log(`An error occurred: ${message}`);
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://belin.io"
},
"devDependencies": {
"@types/node": "^20.11.9",
"@types/node": "^20.11.10",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"del": "^7.1.0",
Expand Down Expand Up @@ -50,8 +50,8 @@
"scripts": {
"build": "node tool/build.js && tsc --project src/tsconfig.json",
"clean": "node tool/clean.js",
"doc": "typedoc --options etc/typedoc.js && node tool/doc.js",
"dist": "npm run clean && npm run build",
"doc": "typedoc --options etc/typedoc.js && node tool/doc.js",
"lint": "tsc --project tsconfig.json && eslint --config=etc/eslint.cjs example src test tool",
"postpublish": "node tool/publish.js",
"prepack": "npm run dist",
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Client {
* @param fields The fields describing the query body.
* @returns The server response.
*/
async #fetch(endpoint: string, fields: Record<string, string>): Promise<Response> {
async #fetch(endpoint: string, fields: Record<string, string[]|string>): Promise<Response> {
const body = new URLSearchParams(this.blog.toJSON());
body.set("api_key", this.apiKey);
if (this.isTest) body.set("is_test", "1");
Expand Down
2 changes: 1 addition & 1 deletion src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Comment {
* Converts this object to a map in JSON format.
* @returns The map in JSON format corresponding to this object.
*/
toJSON(): Record<string, any> {
toJSON(): Record<string, string[]|string> {
const map = this.author ? this.author.toJSON() : {};
if (this.content) map.comment_content = this.content;
if (this.context.length) map.comment_context = this.context;
Expand Down
4 changes: 2 additions & 2 deletions src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class Usage {
*/
static fromJson(json: Record<string, any>): Usage {
return new this({
limit: Number.isInteger(json.limit) ? json.limit : -1,
limit: typeof json.limit == "number" && Number.isInteger(json.limit) ? json.limit : -1,
percentage: typeof json.percentage == "number" ? json.percentage : 0,
throttled: typeof json.throttled == "boolean" ? json.throttled : false,
usage: Number.isInteger(json.usage) ? json.usage : 0
usage: typeof json.usage == "number" && Number.isInteger(json.usage) ? json.usage : 0
});
}
}
Expand Down

0 comments on commit 6f9ddb0

Please sign in to comment.