icon-attention デザイン新しくしました。

icon-calendar 2020年1月26日

【TypeScript】tslintを連続した複数行だけ無効にする

未分類

■tslintがうっとうしくなる場面

例えばExpress-validatorを使用したときこんな感じになってしまう。
流石に改行が多すぎて可読性が下がっている気がします。

router.post(
  "/create",
  [
    body("name")
      .not()
      .isEmpty()
      .trim()
      .escape(),
    body("mail")
      .isEmail()
      .normalizeEmail(),
    body("password")
      .not()
      .isEmpty(),
  ],
  async (req: Express.Request, res: Express.Response) => {
  ...

■コメントで一部改行ができる

router.post(
  "/create",
  [
    // tslint:disable-next-line: prettier
    body("name").not().isEmpty().trim().escape(),
    // tslint:disable-next-line: prettier
    body("mail").isEmail().normalizeEmail(),
    // tslint:disable-next-line: prettier
    body("password").not().isEmpty(),
  ],
  async (req: Express.Request, res: Express.Response) => {
  ...

うーん、毎行コメント挿入はめんどくさい。

■開始位置と終了位置を指定

router.post(
  "/create",
  [
    // tslint:disable
    body("name").not().isEmpty().trim().escape(),
    body("mail").isEmail().normalizeEmail(),
    body("password").not().isEmpty(),
    // tslint:enable
  ],
  async (req: Express.Request, res: Express.Response) => {
  ...

これが一番すっきりしてそう。
もし行数指定の書き方があればそうしたいけど、現時点ではこれで対応。