在VSCode中,是否可以将eslinter格式规则应用于一段代码?

时间:2017-12-18 19:49:35

标签: javascript visual-studio-code eslint

我能够弄清楚如何将eslinter格式化规则应用于整个文件。但是,我希望能够将它仅应用于文件的一部分(选定的代码块)。

我目前已将Atom配置为执行此操作(使用带有ESLint Fixer的Beautify软件包作为Javascript的默认美化程序)。这允许我选择一个代码块并在其上运行Beautify。

我想转到VSCode,但确实需要这个功能。

1 个答案:

答案 0 :(得分:1)

我认为没有直接的方法可以做到这一点。解决方法:

  • let data: Array<any> = [ { id: 1, type: "science", action: "on", name: "title 1", frequency: 10, author: null, }, { id: 3, type: "thriller", action: "off", name: "Programming", frequency: 60, author: 1515202398191, }, { id: 4, type: "article", action: "pause", name: "Stories about life", frequency: 60, author: 1515202398191, }, { id: 5, type: "science", action: "on", name: "Lorem Ipsum", frequency: 60, author: 1515202398191, }, { id: 6, type: "science", action: "off", name: "Testing", frequency: 60, author: 1515202398191, }, { id: 8, type: "science", action: "on", name: "Programming", frequency: 60, author: 1515202398191, } ] function getCount() { let countData: Array<any> = []; data.forEach((item, index) => { let existingItem: any = countData.find((countItem) => { return item.type === countItem.type && item.action === countItem.action; }); if (existingItem) { existingItem.count++; } else { existingItem = { type: item.type, action: item.action, count: 1 }; countData.push(existingItem); } }); return countData; } console.log(getCount()); 放在文件的顶部。然后,在您想要lint的块之前,放置/* eslint-disable */并在块/* eslint-enable */之后。