Skip to content

Commit

Permalink
Port the source code to JS
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Apr 27, 2024
1 parent a88b5ce commit edd5dec
Show file tree
Hide file tree
Showing 15 changed files with 1,231 additions and 852 deletions.
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can verify if you're already good to go with the following command:

```shell
node --version
# v21.7.2
# v22.0.0
```

## Installing with npm package manager
Expand Down
125 changes: 39 additions & 86 deletions etc/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import {join} from "node:path";
import babelParser from "@babel/eslint-parser";
import js from "@eslint/js";
import ts from "typescript-eslint";
import globals from "globals";

export default ts.config(
export default [
js.configs.recommended,
...ts.configs.strictTypeChecked,
...ts.configs.stylisticTypeChecked,
{
languageOptions: {
globals: {...globals.node},
parser: babelParser,
parserOptions: {
project: join(import.meta.dirname, "../tsconfig.json")
requireConfigFile: false,
babelOptions: {
babelrc: false,
configFile: false,
plugins: ["@babel/plugin-syntax-import-attributes"]
}
}
},
rules: {
"array-callback-return": "error",
"no-await-in-loop": "off",
"no-constant-binary-expression": "off",
"no-constructor-return": "error",
"no-duplicate-imports": "error",
"no-new-native-nonconstructor": "error",
"no-promise-executor-return": "off",
"no-inner-declarations": "error",
"no-promise-executor-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-unmodified-loop-condition": "error",
"no-unreachable-loop": "error",
"no-unused-private-class-members": "error",
"no-use-before-define": "off",
"no-use-before-define": ["error", {functions: false}],
// "no-useless-assignment": "error",
"require-atomic-updates": ["error", {allowProperties: true}],

"accessor-pairs": "error",
Expand All @@ -44,33 +48,33 @@ export default ts.config(
"dot-notation": "error",
"eqeqeq": "off",
"func-name-matching": "error",
"func-names": "off",
"func-names": "error",
"func-style": ["error", "declaration", {allowArrowFunctions: true}],
"grouped-accessor-pairs": "error",
"guard-for-in": "error",
"id-denylist": "off",
"id-denylist": "error",
"id-length": ["error", {exceptions: ["_", "x", "y"]}],
"id-match": "error",
"init-declarations": "off",
"init-declarations": "error",
"logical-assignment-operators": "error",
"max-classes-per-file": "off",
"max-depth": "error",
"max-lines": ["error", {max: 500}],
"max-lines-per-function": ["error", {max: 100}],
"max-nested-callbacks": "error",
"max-params": "off",
"max-params": "error",
"max-statements": ["error", {max: 25}],
"multiline-comment-style": ["error", "separate-lines"],
"new-cap": ["error", {capIsNewExceptions: ["RangeError", "SyntaxError", "TypeError"]}],
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "off",
"no-caller": "error",
"no-confusing-arrow": "off",
"no-console": "off",
"no-continue": "off",
"no-div-regex": "error",
"no-else-return": "error",
"no-empty-function": "error",
"no-empty-static-block": "error",
"no-eq-null": "off",
"no-eval": "error",
"no-extend-native": "error",
Expand All @@ -80,13 +84,13 @@ export default ts.config(
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-invalid-this": "off",
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "off",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-multi-assign": ["error", {ignoreNonDeclaration: true}],
"no-multi-str": "error",
Expand All @@ -97,25 +101,25 @@ export default ts.config(
"no-new-wrappers": "error",
"no-object-constructor": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-param-reassign": "error",
"no-plusplus": "off",
"no-proto": "error",
"no-restricted-exports": "off",
"no-restricted-globals": "off",
"no-restricted-imports": "off",
"no-restricted-properties": "off",
"no-restricted-syntax": "off",
"no-return-assign": "off",
"no-restricted-exports": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-script-url": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "off",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
Expand All @@ -128,17 +132,20 @@ export default ts.config(
"one-var": ["error", "never"],
"operator-assignment": "error",
"prefer-arrow-callback": "error",
"prefer-destructuring": "off",
"prefer-const": "error",
"prefer-destructuring": "error",
"prefer-exponentiation-operator": "error",
"prefer-named-capture-group": "off",
"prefer-numeric-literals": "error",
"prefer-object-has-own": "error",
"prefer-object-spread": "error",
"prefer-promise-reject-errors": "error",
"prefer-regex-literals": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"radix": ["error", "as-needed"],
"require-await": "off",
"require-await": "error",
"require-unicode-regexp": "off",
"sort-imports": "off",
"sort-keys": "off",
Expand All @@ -149,61 +156,7 @@ export default ts.config(
"yoda": "error",

"line-comment-position": "error",
"unicode-bom": "error",

"@typescript-eslint/class-literal-property-style": "off",
"@typescript-eslint/class-methods-use-this": "off",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/default-param-last": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {allowExpressions: true}],
"@typescript-eslint/explicit-member-accessibility": ["error", {accessibility: "no-public"}],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/init-declarations": "error",
"@typescript-eslint/max-params": ["error", {max: 4}],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/method-signature-style": "error",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/no-invalid-this": "error",
"@typescript-eslint/no-loop-func": "error",
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-redeclare": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-restricted-imports": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unsafe-unary-minus": "error",
"@typescript-eslint/no-unused-expressions": ["error", {allowTaggedTemplates: true, allowTernary: true}],
"@typescript-eslint/no-use-before-define": ["error", {functions: false}],
"@typescript-eslint/no-useless-empty-export": "error",
"@typescript-eslint/parameter-properties": "error",
"@typescript-eslint/prefer-destructuring": "error",
"@typescript-eslint/prefer-enum-initializers": "off",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/prefer-regexp-exec": "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",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/typedef": "error"
}
},
{
files: ["gulpfile.js", "etc/*.js", "test/**/*.js"],
rules: {
"prefer-arrow-callback": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-floating-promises": "off"
"unicode-bom": "error"
}
}
);
];
5 changes: 3 additions & 2 deletions etc/typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @type {Partial<import("typedoc").TypeDocOptions>}
*/
export default {
entryPoints: ["../src/index.ts"],
entryPoints: ["../src/index.js"],
excludePrivate: true,
gitRevision: "main",
hideGenerator: true,
name: "Akismet for JS",
out: "../docs/api",
readme: "none"
readme: "none",
tsconfig: "../src/jsconfig.json"
};
13 changes: 5 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import replace from "gulp-replace";
import pkg from "./package.json" with {type: "json"};

// Builds the project.
export async function build() {
return $`tsc --project src`;
export function build() {
return $`tsc --project src/jsconfig.json`;
}

// Deletes all generated files.
Expand All @@ -18,14 +18,12 @@ export function clean() {
// Builds the documentation.
export async function doc() {
for (const file of ["CHANGELOG.md", "LICENSE.md"]) await cp(file, `docs/${file.toLowerCase()}`);
await build();
return $`typedoc --options etc/typedoc.js`;
}

// Performs the static analysis of source code.
export async function lint() {
await build();
await $`tsc --project .`;
await $`tsc --project jsconfig.json`;
return $`eslint --config=etc/eslint.config.js gulpfile.js etc example src test`;
}

Expand All @@ -42,14 +40,13 @@ export async function serve() {
}

// Runs the test suite.
export async function test() {
await build();
export function test() {
return $`node --test --test-reporter=spec`;
}

// Updates the version number in the sources.
export function version() {
return gulp.src("src/client.ts")
return gulp.src("src/client.js")
.pipe(replace(/#version = "\d+(\.\d+){2}"/, `#version = "${pkg.version}"`))
.pipe(gulp.dest("src"));
}
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json → jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"include": ["*.js", "etc/*.js", "example/*.js", "src/**/*.ts", "test/**/*.js"],
"exclude": ["etc/eslint.config.js"],
"include": ["*.js", "etc/*.js", "example/*.js", "src/**/*.js", "test/**/*.js"],
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"checkJs": true,
"esModuleInterop": true,
"isolatedModules": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"noImplicitOverride": true,
"resolveJsonModule": true,
"strict": true,
Expand Down
Loading

0 comments on commit edd5dec

Please sign in to comment.