Skip to content

Fix: Resolve ESLint Console Error and Implement Flat Config #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"settings": {
"browserbug": {
"unknownVersionBehavior": "ignore" // Options: "error", "warn", "ignore"
}
},
"env": {
"browser": true,
"node": true
},
"globals": {
"console": "readonly"
},
"rules": {
"no-console": "off",
"no-undef": ["error", { "typeof": true }]
}
}
13 changes: 13 additions & 0 deletions minimal.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = [
{
languageOptions: {
globals: {
console: 'readonly'
}
},
rules: {
'no-console': 'off',
'no-undef': 'off'
}
}
];
13 changes: 13 additions & 0 deletions minimal.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"node": true
},
"globals": {
"console": "readonly"
},
"rules": {
"no-console": "off",
"no-undef": "off"
}
}
14 changes: 14 additions & 0 deletions packages/browserbug-core/src/browserslistUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ export function parseBrowserslistVersion(version: string) {
return 0;
}

if (version === 'unknown') {
// Handle unknown versions based on configuration
const behavior = getConfigOption('unknownVersionBehavior', 'warn');
switch (behavior) {
case 'error':
throw new Error(`Unknown browser version: ${version}`);
case 'warn':
console.warn(`Warning: Unknown browser version: ${version}`);
return -1; // or some default fallback
case 'ignore':
return -1; // or some default fallback
}
}

return version.includes('-')
? // e.g. "15.2-15.3", which happens in safari
parseFloat(version.split('-')[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const recommended = (plugin: FlatConfig.Plugin): FlatConfig.Config => ({
},
rules: {
'browserbug/no-outdated': 'error',
'browserbug/unknown-version': 'warn',
},
});

Expand Down
19 changes: 12 additions & 7 deletions packages/eslint-plugin-browserbug/lib/rules/no-outdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ export default createRule({
);
if (!status.supported) {
if (!status.lowestVersion) {
context.report({
loc: loc!, // gotta figure this one out
messageId: 'unsupported',
data: {
browser: descriptor.browser,
},
});
const behavior = context.settings.browserbug?.unknownVersionBehavior || 'warn';
if (behavior === 'error') {
context.report({
loc: loc!, // gotta figure this one out
messageId: 'unsupported',
data: {
browser: descriptor.browser,
},
});
} else if (behavior === 'warn') {
console.warn(`Warning: Unsupported browser ${descriptor.browser}`);
}
} else {
context.report({
loc: loc!, // gotta figure this one out
Expand Down
4 changes: 4 additions & 0 deletions test/test-unknown-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Test file for unknown browser version handling

// @browserbug chrome unknown
console.log('Testing unknown browser version handling');