javascript - 打字稿缺少分号 linting 错误
问题描述
所以我有一个故事书项目,其故事文件如下:
import { Meta } from '@storybook/react';
// Replacing the <Story/> element with a Story function is also a good way of writing decorators.
// Useful to prevent the full remount of the component's story.
export default {
component: YourComponent,
decorators: [
(Story) => (
<div style={{ margin: '3em' }}>
{Story()}
</div>
),
],
} as Meta;
工作正常,但我在这里收到一个 eslint 错误,} as Meta;
说明后面缺少分号,}
这显然是行不通的。
到目前为止,只有我看到的解决方案建议一起关闭分号 linting 规则。假设我可以对 my 进行简单的调整eslintrc.json
,但还没有遇到过。
eslintrc.json
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
},
"env": {
"browser": true,
"jquery": true,
"es6": true,
"jest": true
},
"extends": [ "eslint:recommended", "plugin:react/recommended" ],
"plugins": [
"react-hooks"
],
"rules": {
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
"block-spacing": "error",
"brace-style": "error",
"comma-spacing": "error",
"complexity": ["error", 21],
"curly": "error",
"dot-location": [
"error",
"property"
],
"guard-for-in": "error",
"indent": [
"error",
2,
{ "SwitchCase": 1 }
],
"key-spacing": "error",
"keyword-spacing": "error",
"lines-between-class-members": "error",
"max-depth": "error",
"new-cap": "error",
"no-eval": "error",
"no-whitespace-before-property": "error",
"react/jsx-tag-spacing": "error",
"react/prop-types": 0,
"semi": [
"error",
"always"
],
"space-before-blocks": "error",
"space-infix-ops": "error"
},
"globals": {
"process": true,
"maestroStrings": true,
"GLOBAL_BrowserTimeZone": true,
"profiseeConfig": true,
"Mdm": true,
"apiRequestVerificationToken": true,
"LoadReportPart": true,
"FilterSortDialog": true,
"module": true,
"global": true,
"_profHandling401": true
}
}
解决方案
这应该有效:
const Meta = {
component: YourComponent,
decorators: [
(Story) => (
<div style={{ margin: '3em' }}>
{Story()}
</div>
),
],
};
export { Meta as default };
如果您想要命名导出,您还可以执行以下操作:
export const Meta = {
component: YourComponent,
decorators: [
(Story) => (
<div style={{ margin: '3em' }}>
{Story()}
</div>
),
],
};
推荐阅读
- php - 在 PHP 中,如何从具有多个键的多维数组中访问数据
- azure-sql-database - 如何使用 Powershell 获取 SQL MI 实例的已用空间
- nginx - 无法重新加载 Nginx 上下文
- typescript - 找不到模块 - 打字稿路径别名错误
- php - jquery Ajax没有保存到mysql
- node.js - text2wav MIME 类型错误 wasm 编译问题?
- javascript - 如何单击包含文本的链接
- angular - 使用 Angular 从 ag-grid-community 迁移到 ag-grid-enterprise
- image - 我正在尝试使用 ASP.NET Core 3.0 MVC 上传图像
- android - Android Gradle 实施项目(':项目名称')不起作用