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

2022 Q4修订 #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

2022 Q4修订 #64

wants to merge 5 commits into from

Conversation

otakustay
Copy link
Member

No description provided.

}
```

### 【强制】要求适当处理类似 Promise 的语句 @佘采华

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn 的规则应该是 [推荐]

#### [强制] 标签使用必须符合标签嵌套规则。

解释:

比如 `div` 不得置于 `p` 中,`tbody` 必须置于 `table` 中。

详细的标签嵌套规则参见[HTML DTD](http://www.cs.tut.fi/~jkorpela/html5.dtd)中的 `Elements` 定义部分。

详细的标签嵌套规则参见[HTMLf外](https://html.spec.whatwg.org/multipage/)中各元素定义的“Content model”说明。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HTMLf外]是啥

@@ -837,6 +567,18 @@ viewport meta tag 可以设置可视区域的宽度和初始缩放大小,避
</table>
```

#### [强制] 新窗口/标签页打开的链接需要按业务需要添加安全相关的 `rel` 属性值 `noopener`。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是需要增加 noreferrer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不,noreferrer是业务诉求,noopener是安全诉求,不考虑在编码规范上去要求业务怎么样


对于函数声明(Function Declaration)、类声明(Class Declaration),它们不属于语句(Statement),因此不需要以分号结束。

对于 `export default` 语句,参考其后部分的类型,如果是函数、类声明,同样不需要分号。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有export都适用,不一定要export default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我想named export应该不会有人误解,export default比较特殊些所以特别说明


除去不定长参数以外,函数具备不同逻辑意义的参数建议控制在 `6` 个以内,过多参数会导致维护难度增大
##### [建议] 一个函数的参数控制在 **6**** 个以内。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多了两个星号

}
```

### [强制]禁止不必要的类型约束

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相关讨论:#65

我理解 lint 的职责一方面是统一代码格式,另一方面就是引导使用者写出简洁的代码。
像上面的一系列『禁止不必要……』就很好的体现了这一点。与『不必要的断言』、『不必要的参数』不同的地方是,类型约束在某些场景下是必要的 ,就像我上面举的例子中,它关乎到能否正确解析代码。即便这个必要是由于语法缺陷导致的,但这确实是一个会遇到的场景。
与它类似的,就像 const a = ({}) 是不必要的圆括号,而 () => ({}) 是有必要的一样的。在 tsx 文件中写带有泛型的箭头函数,这个事情本身没有什么不合理之处。如果强制禁止,会否让开发者太过受限,而背离了写简洁代码的初衷。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考 typescript-eslint/typescript-eslint#4062 ,官方似乎并没有修正的想法,我们可以考虑ts和tsx使用不同的规则

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

Successfully merging this pull request may close these issues.

3 participants