Skip to content

Require throws isn't working for static methods in a class #854

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

Closed
ghost opened this issue Mar 23, 2022 · 10 comments
Closed

Require throws isn't working for static methods in a class #854

ghost opened this issue Mar 23, 2022 · 10 comments

Comments

@ghost
Copy link

ghost commented Mar 23, 2022

Expected behavior

For ESLint lint to detect that I don't have a throw statement

Actual behavior

ESLint lint has 0 errors. Other files with missing JSDoc throws is detected, but not this method.

ESLint Config

{
    "env": {
        "browser": true,
        "es2021": true,
        "node": true
    },
    "extends": [
        "plugin:react/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint",
        "jsdoc"
    ],
    "rules": {
        "indent": ["error", "tab"],
        "@typescript-eslint/indent": ["error", "tab"],
        "@typescript-eslint/explicit-member-accessibility": ["error", {
            "accessibility": "explicit"
        }],
        "jsdoc/require-description-complete-sentence": ["error"],
        "jsdoc/check-alignment": ["error"],
        "jsdoc/no-types": ["error"],
        "jsdoc/check-param-names": ["error"],
        "jsdoc/require-property-description": ["error"],
        "jsdoc/require-param": ["error"],
        "jsdoc/require-param-description": ["error"],
        "jsdoc/require-throws": ["error"],
        "jsdoc/require-returns": ["error"],
        "jsdoc/require-returns-description": ["error"],
        "jsdoc/require-jsdoc": ["error", {
            "contexts": [
                "TSInterfaceDeclaration",
                "TSTypeAliasDeclaration",
                "TSEnumDeclaration",
                "TSMethodSignature",
                "TSPropertySignature",
                "TSConstructorDeclaration",
                "TSCallSignatureDeclaration",
                "TSIndexSignature",
                "TSMethodDeclaration",
                "TSGetAccessorDeclaration",
                "TSSetAccessorDeclaration",
                "TSDeclareFunction",
                "TSDeclareMethod",
                "TSDeclareModule",
                "TSModuleBlock",
                "TSModuleDeclaration",
                "TSImportEqualsDeclaration",
                "TSImportType",
                "TSExportAssignment",
                "TSExportDeclaration",
                "TSNamespaceExportDeclaration",
                "TSInterfaceDeclaration",
                "TSTypeAliasDeclaration",
                "TSEnumDeclaration",
                "TSMethodSignature",
                "TSPropertySignature",
                "TSConstructorDeclaration",
                "TSCallSignatureDeclaration",
                "TSIndexSignature",
                "TSMethodDeclaration",
                "TSGetAccessorDeclaration",
                "TSSetAccessorDeclaration",
                "TSDeclareFunction",
                "TSDeclareMethod",
                "TSDeclareModule",
                "TSModuleBlock",
                "TSModuleDeclaration",
                "TSImportEqualsDeclaration",
                "TSImportType",
                "TSExportAssignment",
                "TSExportDeclaration",
                "TSNamespaceExportDeclaration"
            ]
        }],
        "prefer-template": "error",
        "require-jsdoc": ["error", {
            "require": {
                "FunctionDeclaration": true,
                "MethodDefinition": true,
                "ClassDeclaration": true
            }
        }],
        "@typescript-eslint/semi": ["error", "always"],
        "@typescript-eslint/no-underscore-dangle": ["off"],
        "@typescript-eslint/comma-dangle": ["error"]
    }
//    "settings": {
//        "jsdoc": {
//            "tagNamePreference": {
//                // TODO: Open an issue on eslint-plugin-jsdoc to fix support for disabling @private
//                "private": false
//            }
//        }
//    }
}
import type ESBuild from 'esbuild';
import Errors from './Errors';
import {Settings} from './Settings';
import mergeDeep from '@hyper-stack/merge-deep';
import {PartialDeep} from 'type-fest';
import {HyperError} from '@hyper-stack/internal';

/**
 * A class used for importing TypeScript files into NodeJS without the need for pre-compiling.@throws {HyperError<Errors>}.
 */
export default class TSImport {
	/**
	 * Compile an entry file.
	 * @param inputSourcePath The TypeScript input source.
	 * @param outputSourcePath The output source path.
	 * @param settings Settings for the import.
	 */
	public static async compile(inputSourcePath: string, outputSourcePath: string, settings: PartialDeep<Settings> = {}) {
		const esBuild = await import(['es', 'build'].join('')) as typeof ESBuild;

		const settingsFull = mergeDeep<Settings, PartialDeep<Settings>>({
			externals: [],
			format: 'esm',
			target: 'ESNext'
		}, settings);

		let buildResult: ESBuild.BuildResult;

		try {
			buildResult = await esBuild.build({
				entryPoints: [inputSourcePath],
				outfile: outputSourcePath,
				format: settingsFull.format,
				target: settingsFull.target,
				bundle: true,
				logLevel: 'silent',
				allowOverwrite: true,
				platform: 'node',
				external: settingsFull.externals,
				treeShaking: true
			});
		} catch (error) {
			throw new HyperError(Errors.ESBUILD_BUILD_FAILED, `ESBuild failed to compile the source file, the following error message was returned: ${(error as Error).message}`);
		}
	}
}

export {Errors, Settings};

Environment

  • Node version: 17.4.0
  • ESLint version 8.0.0-rc.0
  • eslint-plugin-jsdoc version: 38.0.6
@ghost ghost added the bug-unconfirmed label Mar 23, 2022
@ghost
Copy link
Author

ghost commented Mar 23, 2022

REASON FOUND: When I removed async it fixed it, but I want throw requirements for async methods, any option I need?

@ghost
Copy link
Author

ghost commented Mar 23, 2022

I found no settings for the option, I just have "error"

@brettz9
Copy link
Collaborator

brettz9 commented Mar 23, 2022

The reason for this is that async functions technically don't throw. They just issue rejected Promises. Unfortunately, we would still need to support #755 for there to be a way to indicate the types of rejections.

See also https://stackoverflow.com/questions/50071115/typescript-promise-rejection-type on how TypeScript doesn't currently offer such an ability either.

@ghost
Copy link
Author

ghost commented Mar 23, 2022

Alright thankyou!

@brettz9 brettz9 closed this as completed Mar 23, 2022
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Mar 23, 2022
@gajus
Copy link
Owner

gajus commented Mar 26, 2022

🎉 This issue has been resolved in version 38.0.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Mar 26, 2022
@ghost
Copy link
Author

ghost commented Mar 28, 2022

Issue still seems to be happening

@brettz9
Copy link
Collaborator

brettz9 commented Mar 28, 2022

Did you restart your IDE?

@ghost
Copy link
Author

ghost commented Mar 28, 2022

yes

@brettz9
Copy link
Collaborator

brettz9 commented Mar 28, 2022

Oh, sorry... As per above, the throwing is not really throwing. The "fixing" in this issue is related to the fact that we now have docs explaining it.

@ghost
Copy link
Author

ghost commented Mar 28, 2022

Oh, alright xD
the release notes didn't explain anything lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants