Skip to content

Commit

Permalink
feat(evolver): ensure async methods work correctly when chained
Browse files Browse the repository at this point in the history
modify chained methods so async/sync have different chaining names

BREAKING CHANGE: .
  • Loading branch information
Jake Lauer authored and Jake Lauer committed Jul 23, 2024
1 parent 3601bf6 commit 4040fbe
Show file tree
Hide file tree
Showing 14 changed files with 476 additions and 292 deletions.
148 changes: 78 additions & 70 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,81 +1,89 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
parser: "@typescript-eslint/parser",
parserOptions: {
project: [
"./.examples/tic-tac-toe/tsconfig.json",
"./tsconfig.tsup.json",
"./tsconfig.base.json",
"./packages/commitlint-config/tsconfig.json",
"./packages/sandbox/tsconfig.tsup.json",
"./packages/sandbox/tsconfig.json",
"./packages/logger/tsconfig.json",
"./packages/logger/tsconfig.tsup.json",
"./packages/eslint-plugin-theseus/tsconfig.json",
"./tsconfig.json"
],
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: "./",
},
extends: [
"./.examples/tic-tac-toe/tsconfig.json",
"./tsconfig.tsup.json",
"./tsconfig.base.json",
"./packages/commitlint-config/tsconfig.json",
"./packages/sandbox/tsconfig.tsup.json",
"./packages/sandbox/tsconfig.json",
"./packages/logger/tsconfig.json",
"./packages/logger/tsconfig.tsup.json",
"./packages/eslint-plugin-theseus/tsconfig.json",
"./tsconfig.json",
],
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: "./",
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:theseus/recommended",
"plugin:require-extensions/recommended"
],
settings: {
'import/resolver': {
node: {
paths: ["eslint-rules"]
}
}
},
plugins: ["unused-imports", "@stylistic", "require-extensions"],
rules: {
"indent": ["error", "tab", { "SwitchCase": 1 }],
quotes: [2, "double", { avoidEscape: true }],
"unused-imports/no-unused-imports": "error",
"no-async-promise-executor": "off",
"@stylistic/object-property-newline": ["error"],
"@stylistic/object-curly-newline": ["error", {
"ObjectExpression": { "multiline": true, "minProperties": 1 },
"ObjectPattern": { "multiline": true, "minProperties": 3 },
"ImportDeclaration": { "multiline": true, "minProperties": 3 },
"ExportDeclaration": { "multiline": true, "minProperties": 2 }
}],
"@typescript-eslint/no-floating-promises": ["error"],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
"plugin:theseus/recommended",
"plugin:require-extensions/recommended",
],
settings: {
"import/resolver": {
node: {
paths: ["eslint-rules"],
},
},
},
plugins: ["unused-imports", "@stylistic", "require-extensions"],
rules: {
indent: ["error", "tab", { SwitchCase: 1 }],
quotes: [2, "double", { avoidEscape: true }],
"unused-imports/no-unused-imports": "error",
"no-async-promise-executor": "off",
"@stylistic/object-property-newline": ["error"],
"@stylistic/object-curly-newline": [
"error",
{
ObjectExpression: { multiline: true, minProperties: 1 },
ObjectPattern: { multiline: true, minProperties: 3 },
ImportDeclaration: { multiline: true, minProperties: 3 },
ExportDeclaration: { multiline: true, minProperties: 2 },
},
],
"@typescript-eslint/no-floating-promises": [
"error",
{
checkThenables: true,
},
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"semi": ["error", "always"],
semi: ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"array-bracket-spacing": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"max-len": ["error", { "code": 180, "ignoreUrls": true, "ignoreTemplateLiterals": true, "ignoreStrings": true }],
"max-len": ["error", { code: 180, ignoreUrls: true, ignoreTemplateLiterals: true, ignoreStrings: true }],
"arrow-parens": ["error", "always"],
"no-tabs": "off", // Since you're using tabs
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"keyword-spacing": ["error", { "before": true, "after": true }],
"brace-style": ["error", "allman", { "allowSingleLine": true }],
},
overrides: [
{
files: ["**/*.test.ts"],
rules: {
"@typescript-eslint/no-unused-vars": ["off"],
},
},
],
"key-spacing": ["error", { beforeColon: false, afterColon: true }],
"keyword-spacing": ["error", { before: true, after: true }],
"brace-style": ["error", "allman", { allowSingleLine: true }],
},
overrides: [
{
files: ["**/*.test.ts"],
rules: {
"@typescript-eslint/no-unused-vars": ["off"],
},
},
],
};
64 changes: 32 additions & 32 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"exportall.config.relExclusion": ["/lib/Types/Modifiers.ts"],
"javascript.preferences.importModuleSpecifier": "relative",
"javascript.preferences.importModuleSpecifierEnding": "minimal",
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifierEnding": "minimal",
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.suggest.paths": true,
"search.exclude": {
"dist/": true
},
"files.exclude": {
// "dist/": true,
//"**/node_modules/**": true
},
"tsimporter.doubleQuotes": true,
"typescript.preferences.quoteStyle": "double",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[xml]": {
"editor.defaultFormatter": "redhat.vscode-xml"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"exportall.config.relExclusion": [ "/lib/Types/Modifiers.ts" ],
"javascript.preferences.importModuleSpecifier": "relative",
"javascript.preferences.importModuleSpecifierEnding": "minimal",
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifierEnding": "minimal",
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.suggest.paths": true,
"search.exclude": {
"dist/": true
},
"files.exclude": {
// "dist/": true,
//"**/node_modules/**": true
},
"tsimporter.doubleQuotes": true,
"typescript.preferences.quoteStyle": "double",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"eslint.validate": [ "javascript", "javascriptreact", "typescript", "typescriptreact" ],
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[xml]": {
"editor.defaultFormatter": "redhat.vscode-xml"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "node_modules/typescript/lib",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"@types/sinon": "^17.0.3",
"@types/ungap__structured-clone": "^1.2.0",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@vitest/coverage-v8": "^1.0.1",
"chai-as-promised": "^7.1.1",
"commitizen": "^4.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ ruleTester.run("break-on-chainable", rule, {
// If an ending method is used without chaining, don't force a line break
code: "obj.via.thing().end()",
},
{
code: "obj.via.thing().endAsync()",
},
{
// If no `.via` is present, we're not interested in the chain
code: "obj.thing().and.anotherThing().lastly.thing();",
},
{
// Properly handling async methods
code: "async () => { await obj.via.thing().endAsync(); }",
},
],
invalid: [
{
Expand Down Expand Up @@ -62,6 +63,9 @@ ruleTester.run("break-on-chainable", rule, {
{
message: "Expected line break before `.and`.",
},
// {
// message: "Detected floating promise for `.endAsync`. Await or handle the promise properly.",
// },
{
message: "Expected line break before `.endAsync`.",
},
Expand All @@ -80,5 +84,41 @@ ruleTester.run("break-on-chainable", rule, {
],
output: "GameMeta.evolve.iterateTurnCount()\n.and.updateLastPlayer(mark)\n.and.updateLastPlayedCoords(coords);",
},
// {
// code: "obj.via.thing()\n.andAsync();",
// errors: [
// {
// message: "Detected floating promise for `.andAsync`. Await or handle the promise properly.",
// },
// ],
// },
// {
// code: "obj.via.thing().lastlyAsync();",
// errors: [
// {
// message: "Detected floating promise for `.lastlyAsync`. Await or handle the promise properly.",
// },
// {
// message: "Expected line break before `.lastlyAsync`.",
// },
// ],
// output: "obj.via.thing()\n.lastlyAsync();",
// },
// {
// code: "obj.via.thing()\n.lastlyAsync();",
// errors: [
// {
// message: "Detected floating promise for `.lastlyAsync`. Await or handle the promise properly.",
// },
// ],
// },
// {
// code: "evolver2.evolve(input).via.double()\n.andAsync.double();",
// errors: [
// {
// message: "Detected floating promise for `.andAsync`. Await or handle the promise properly.",
// },
// ],
// },
],
});
3 changes: 3 additions & 0 deletions packages/eslint-plugin-theseus/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
],
rules: {
"theseus/break-on-chainable": "error",
"@typescript-eslint/no-floating-promises": ["error", {
checkThenables: true,
}],
},
},
},
Expand Down
Loading

0 comments on commit 4040fbe

Please sign in to comment.