Upgrade to Pro — share decks privately, control downloads, hide ads and more …

@cybozu/eslint-configから学ぶ、全社共通ESLint configの運用

Hiroyuki ANAI
February 10, 2021

@cybozu/eslint-configから学ぶ、全社共通ESLint configの運用

The lightning talk for フロントエンドカンファレンス福岡スピンオフ テーマ: ESLint
https://fec-fukuoka.connpass.com/event/201334/

Hiroyuki ANAI

February 10, 2021
Tweet

More Decks by Hiroyuki ANAI

Other Decks in Programming

Transcript

  1. ςετίʔυྫ ςετͷίʔυ 1 const assert = require("assert"); 2 const runLintWithFixtures

    = require("./lib/runLintWithFixtures"); 3 4 describe("node", () => { 5 it("should get expected errors and warninigs with node config", async () => { 6 const result = await runLintWithFixtures("node"); 7 assert.deepStrictEqual(result, { 8 "error.js": { 9 errors: [ 10 "node/no-missing-require", 11 "node/no-unsupported-features/es-syntax", 12 ], 13 }, 14 "ok.js": {}, 15 }); 16 }); 17 }); ૝ఆͨ͠ΤϥʔΛు͍͍ͯΔ͔
  2. ςετίʔυྫ ςετͷίʔυ 1 "use strict"; 2 3 const { ESLint

    } = require("eslint"); 4 const path = require("path"); 5 6 /** 7 * Run ESlint and return the result per files 8 * @param type lint type, which is in lib directory 9 * @returns {Object} … 10 */ 11 const runLintWithFixtures = async (type, configFile = `lib/${type}.js`) => { 12 const eslint = new ESLint({ 13 overrideConfigFile: path.resolve(process.cwd(), configFile), 14 ignore: false, 15 useEslintrc: false, 16 extensions: [".js", ".jsx", ".ts", ".tsx"] 17 }); 18 const targetDir = path.resolve(__dirname, "..", "fixtures", type); 19 const lintResult = await eslint.lintFiles([targetDir]); 20 // console.log(JSON.stringify(lintResult, null, 2)); 21 return lintResult.reduce((results, { filePath, messages }) => { … }, {}); 22 }; 23 24 module.exports = runLintWithFixtures; ςετ༻ͷ+4ϑΝΠϧʹରͯ͠&4-JOUΛ࣮ߦ
  3. ͦͷଞ w 3FOPWBUFΛઃఆ w ϝϯςޮ཰Λ্͛Δ w ઃఆˠIUUQTHJUIVCDPNDZCP[VSFOPWBUFDPOpH w ར༻ଆʹ΋ઃఆͯ͋͠Δͱঘྑ w

    ϝϯς͢Δਓ͕ܾ·͍ͬͯΔ w લ৬Ͱ͸୭΋ϝϯς͠ͳ͘ͳͬͨ w ۀ຿ͱͯ͠ϝϯς͢Δਓ͕ܾ·͍ͬͯΔํ͕͏·͍͖ͦ͘͏