- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些使用大量条件的旧 React 代码,例如使用 LET 设置变量,然后使用 if/else 来应用值。
为了可读性,我想将其更改为在有意义的地方使用逻辑运算符。
是否有可以自动执行此操作的 linter/格式化程序?
包含示例代码。
目前还不能用 ESlint 或 prettier 做到这一点。
let method
if (play && play.show_question) method = 'question'
else if (play && play.show_answer) method = 'answer'
用linter,自动转换成
const method = play && play.show_question ? 'question' : play && play.show_answer && 'answer'
如果存在可以自动重构它的格式化程序/插件/linter,请告诉我
最佳答案
您可以先检查play
,然后再选择问题部分或答案部分。
const method = play && (play.show_question && 'question' || play.show_answer && 'answer');
要获得定义的假值,您可以添加一个默认值,例如 undefined
const
method = play && (play.show_question && 'question' || play.show_answer && 'answer')
|| undefined;
关于javascript - 使用 JS linter/formatter 将条件(else/if)运算符转换为逻辑运算符(&& ||)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55318236/
我向我的记录器添加了两个具有不同格式化程序的处理程序。第一个需要继承 logging.Formatter 来进行自定义格式化。默认格式化程序将满足第二个处理程序的需要。 假设第一个格式化程序只是从消息
我尝试运行一个简单的 .feature 文件以生成 Step 文件所需的代码,但返回以下异常: 下面是pom文件: org.seleniumhq.selenium
userA 在法国,他们将某样东西的价格定为 10 欧元,我获取他们的货币信息,并使用 Locale.current.identifier 将其本地区域的副本记录到数据库,这给出了我 € 并将其保存到
我已经在 android 项目上集成了 checkstyle。但是我收到以下错误: > Unable to create listeners: formatters {[com.puppycrawl.
这个解决方案对我不起作用: Running a spec in RubyMine results in "cannot load such file -- teamcity/spec/runner/f
我正在尝试在 Eclipse 中设置我的第一个 Cucumber。我按照教程视频建议的方式在 Features 文件夹中设置了一个基本功能文件,但尝试作为 cucumber 功能执行时,我得到以下信息
操作系统:Arch Linux,Rails 版本:4,RubyMine:6.3 当我从 Tools - Run Rake Task - spec 运行规范时,我总是会收到此错误: /home/chyl
我正在尝试使用 formattable Awesome 包并获得一个表格,其中包含在多列上缩放的百分比和颜色。 这里是代码 set.seed(123) df % mutate_if(is.nume
我试图将字符串定位在一行上的某个起始位置,无论前一个文本在哪里结束。例如: Mandatory arguments to long options are mandatory for short op
因此,我将以下代码写入文件: Formatter output = ....... // Creating the formatter works, writes to appropriate fil
我知道有很多 HTML 格式化程序。我已经尝试了很多,但没有一个符合我的要求。请建议您是否遇到了可以: 1) 转换 BBCC 进入 BB
在本文中,我们将介绍 Java Formatter.format 方法。 java.util.Formatter 类用作 printf 样式格式字符串的解释器。 Formatter 可以执行布局对齐、
我有一个简单的验证器,可以根据正则表达式检查输入: .directive('test', function () { return { restrict: 'A', require:
假设您有一些表格数据,其中数据长度可能会有所不同,Formatter 类是否有自动调整填充的规定? 所以不是这个(注意 A 列): columnA columnB 1
我有一个这样注释的模型: [DataMember(EmitDefaultValue = false)] [JsonProperty("extension_{0}_name")] public stri
示例数据(修改自 formattable github 文档): df <- data.frame( id = 1:10, name = c("Bob", "Ashley", "James",
我编写了下面的代码,它创建了一个文件并完美地写入它,但我想在输出中查看文件的内容,但我只收到此消息:“java.io.BufferedWriter@140e19d”。我不明白!谁能向我解释一下为什么我
我有兴趣使用 formattable R 包中的工具,但我只想在表格中显示有更改的地方。也就是说,我想要通过 collapse_rows() 函数在 kableExtra 包中提供分层行标签。 例如,
我已经开始使用 Intellij (之前使用过 Eclipse),但我似乎无法模仿 Eclipse 格式 Eclipse Code Formatter 插件完成了大部分工作,但仍然存在一些差异。 例如
我是编码新手,有一个问题如何修复此代码以实际使用用户输入作为创建的文件的新名称。如您所见,我希望在格式化程序中使用字符串“文件名”(例如,输入是“Example.txt”,这应该在格式化程序的构造函数
我是一名优秀的程序员,十分优秀!