Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] Migrate project to TypeScript #766

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ root = true
charset = utf-8
indent_style = tab

[*.{css,html,js,cjs,mjs,jsx,ts,tsx,less,txt,json,yml,md}]
[*.{css,html,js,cjs,mjs,jsx,ts,cts,mts,tsx,less,txt,json,yml,md}]
trim_trailing_whitespace = true
end_of_line = lf
indent_size = 4
Expand Down
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
build/** -linguist-generated=false
lib/build/** linguist-generated=false
lib/** linguist-vendored=false
lib/** linguist-generated=false
lib/** linguist-generated=false
src/build/** linguist-generated=false
src/** linguist-vendored=false
src/** linguist-generated=false
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ build/Release
node_modules
jspm_packages

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

Expand All @@ -61,3 +64,6 @@ deploy_key
!test/fixtures/**/node_modules
test/tmp/
jsdocs/

# Generated code
/lib/
30 changes: 30 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"reporter": ["lcov", "text", "text-summary"],
"include": ["src/**"],
"check-coverage": true,
"statements": 90,
"branches": 85,
"functions": 90,
"lines": 90,
"watermarks": {
"statements": [
70,
90
],
"branches": [
70,
90
],
"functions": [
70,
90
],
"lines": [
70,
90
]
},
"cache": true,
"all": true
}
23 changes: 23 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Calculate nodeArguments based on the Node version
const nodeArguments = [
"--import=tsx/esm",
"--no-warnings=ExperimentalWarning",
];

export default {
extensions: {
ts: "module",
},
files: [
"test/lib/**/*.ts",
"!test/**/__helper__/**",
],
watchMode: {
ignoreChanges: [
"test/tmp/**",
"lib/**",
],
},
nodeArguments,
workerThreads: false,
};
230 changes: 139 additions & 91 deletions eslint.common.config.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,147 @@
import jsdoc from "eslint-plugin-jsdoc";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import stylistic from "@stylistic/eslint-plugin";
import ava from "eslint-plugin-ava";
import globals from "globals";
import js from "@eslint/js";
import google from "eslint-config-google";

export default [{
ignores: [ // Common ignore patterns across all tooling repos
"**/coverage/",
"test/tmp/",
"test/expected/",
"test/fixtures/",
"**/docs/",
"**/jsdocs/",
],
}, js.configs.recommended, google, ava.configs["flat/recommended"], {
name: "Common ESLint config used for all tooling repos",
import jsdoc from "eslint-plugin-jsdoc";

plugins: {
jsdoc,
},
export default tseslint.config(
{
// This block defines ignore patterns globally to all configurations below
// (therefore it can use slightly different patterns, see also the eslint "Flat Config" doc)
ignores: [
".github/*",
".reuse/*",
"coverage/*",
"**/docs/",
"**/jsdocs/",

languageOptions: {
globals: {
...globals.node,
},
// Exclude test files
"test/tmp/*",
"test/fixtures/*",
"test/expected/*",

ecmaVersion: 2023,
sourceType: "module",
// Exclude generated code
"lib/*",
],
},

settings: {
jsdoc: {
mode: "jsdoc",

tagNamePreference: {
return: "returns",
augments: "extends",
// Base configs applying to JS and TS files
eslint.configs.recommended,
stylistic.configs.customize({
indent: "tab",
quotes: "double",
semi: true,
jsx: false,
arrowParens: true,
braceStyle: "1tbs",
blockSpacing: false,
}),
ava.configs["flat/recommended"], {
// Lint all JS files using the eslint parser
files: ["**/*.js"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
}, {
// Lint all TS files using the typescript-eslint parser
// Also enable all recommended typescript-eslint rules
files: ["src/**/*.ts", "test/**/*.ts", "scripts/**/*.ts"],
extends: [
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
},

rules: {
"indent": ["error", "tab"],
"linebreak-style": ["error", "unix"],

"quotes": ["error", "double", {
allowTemplateLiterals: true,
}],

"semi": ["error", "always"],
"no-negated-condition": "off",
"require-jsdoc": "off",
"no-mixed-requires": "off",

"max-len": ["error", {
code: 120,
ignoreUrls: true,
ignoreRegExpLiterals: true,
}],

"no-implicit-coercion": [2, {
allow: ["!!"],
}],

"comma-dangle": "off",
"no-tabs": "off",
"no-console": 2, // Disallow console.log()
"no-eval": 2,
// The following rule must be disabled as of ESLint 9.
// It's removed and causes issues when present
// https://eslint.org/docs/latest/rules/valid-jsdoc
"valid-jsdoc": 0,
"jsdoc/check-examples": 0,
"jsdoc/check-param-names": 2,
"jsdoc/check-tag-names": 2,
"jsdoc/check-types": 2,
"jsdoc/no-undefined-types": 0,
"jsdoc/require-description": 0,
"jsdoc/require-description-complete-sentence": 0,
"jsdoc/require-example": 0,
"jsdoc/require-hyphen-before-param-description": 0,
"jsdoc/require-param": 2,
"jsdoc/require-param-description": 0,
"jsdoc/require-param-name": 2,
"jsdoc/require-param-type": 2,
"jsdoc/require-returns": 0,
"jsdoc/require-returns-description": 0,
"jsdoc/require-returns-type": 2,

"jsdoc/tag-lines": [2, "any", {
startLines: 1,
}],
rules: {
// TypeScript specific overwrites
// We must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/consistent-type-imports": ["error", {
fixStyle: "inline-type-imports",
}],
"@typescript-eslint/consistent-type-exports": ["error", {
fixMixedExportsWithInlineTypeSpecifier: true,
}],
"@typescript-eslint/no-unused-vars": [
"error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
},
}, {
// To be discussed: Type-aware checks might add quite some additional work when writing tests
// and could even require us to export types that we would otherwise not export
files: ["test/**/*.ts"],
rules: {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-unary-minus": "off",
},
}, {
// Overwrite any rules from the configurations above for both, JS and TS files
rules: {
"linebreak-style": [
"error",
"unix",
],
"@stylistic/object-curly-spacing": [
"error",
"never",
],
"@stylistic/operator-linebreak": ["error", "after"],
"@stylistic/comma-dangle": ["error", {
functions: "never",
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
enums: "always-multiline",
generics: "always-multiline",
tuples: "always-multiline",
}],
"max-len": [
"error",
{
code: 120,
ignoreUrls: true,
ignoreRegExpLiterals: true,
},
],
"no-implicit-coercion": [
"error",
{allow: ["!!"]},
],
"no-console": "error",
"no-eval": "error",

"jsdoc/valid-types": 0,
"ava/assertion-arguments": 0,
},
}
];
"valid-jsdoc": "off",
},
}, {
// JSdoc only applying to sources
files: ["src/**/*.ts"],
...jsdoc.configs["flat/recommended-typescript-error"],
}, {
// Overwriting JSDoc rules in a separate config with the same files pattern
files: ["src/**/*.ts"],
rules: {
"jsdoc/require-jsdoc": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-description": "off",
"jsdoc/tag-lines": ["error", "any", {
startLines: 1,
}],
},
}
);
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default [
{
// Add project-specific ESLint config rules here
// in order to override common config
}
},
];
9 changes: 0 additions & 9 deletions jsdoc-plugin.cjs

This file was deleted.

Loading
Loading