Skip to content

Commit

Permalink
fix no-numeric-separators crashing
Browse files Browse the repository at this point in the history
Co-authored-by: Kristján Oddsson <[email protected]>
  • Loading branch information
keithamus and koddsson committed Oct 17, 2022
1 parent fe64372 commit b7c7dbb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ const path = require('path')
const browserslist = require('browserslist')
const {findConfig} = require('browserslist/node')
const {version,homepage} = require('../package.json')
const createRule = (name, browserstring, description, {fixable = null, schema = [], ts = null} = {}) => {
const createRule = (name, browserstring, description, {ts = null} = {}) => {
const rule = require(`./rules/${name}`)
module.exports.rules[name] = {
meta: {
meta: Object.assign({
type: 'problem',
docs: {
description,
recommended: true,
url: `${homepage}/blob/v${version}/docs/${name}.md`
},
fixable,
schema,
fixable: false,
schema: [],
deprecated: false,
replacedBy: null,
},
}, rule.meta || {}),
create(context) {
let browsers = browserslist(browserstring)
const config = findConfig(path.dirname(context.getFilename())) || { defaults: 'defaults' }
const desiredBrowsers = browserslist(config.defaults)
const badBrowsers = desiredBrowsers.filter(browser => browsers.indexOf(browser) !== -1).join(', ')
if (badBrowsers) {
return require(`./rules/${name}`)(context, badBrowsers)
const create = typeof rule === 'function' ? rule : rule.create
return create(context, badBrowsers)
}
return {}
}
Expand Down Expand Up @@ -70,7 +72,7 @@ createRule('no-nullish-coalescing', 'edge < 80, safari < 13.1, firefox < 72, chr
createRule('no-bigint', 'edge < 79, safari < 14, firefox < 68, chrome < 67', 'disallow bigints')

// ES2021
createRule('no-numeric-separators', 'edge < 79, safari < 13, firefox < 68, chrome < 75', 'disallow use of numeric seperators like 1_000_000', {fixable: true, ts:2021})
createRule('no-numeric-separators', 'edge < 79, safari < 13, firefox < 68, chrome < 75', 'disallow use of numeric seperators like 1_000_000', {ts:2021})

// ES2022
createRule('no-public-static-class-fields', 'edge < 79, safari < 14.5, firefox < 75, chrome < 72', 'disallow public static class fields like foo = 1', {ts: 2022})
Expand Down

0 comments on commit b7c7dbb

Please sign in to comment.