lint: minor formatting issue with catch(e)

The custom eslint pluggin for the formatting rule I have for the
expressions in control structures isn't a good fit when the condition is
a single variable named by a single character. This happens a lot with
`catch`. `catch ( e ) {` has too much spacing, but `catch (e) {` looks
relatively normal.
This commit is contained in:
KernelDeimos
2025-09-25 12:26:59 -04:00
parent 62e77a15a2
commit 7b4c62d1c3
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -46,6 +46,16 @@ export default {
const afterOpen = sourceCode.getTokenAfter(openParen);
const beforeClose = sourceCode.getTokenBefore(closeParen);
{
const contentBetweenParens = sourceCode.getText().slice(openParen.range[1], closeParen.range[0]);
const isSingleCharVariable = /^\s*[a-zA-Z_$]\s*$/.test(contentBetweenParens);
// Skip spacing requirements for single character variables
if ( isSingleCharVariable ) {
return;
}
}
// Control structures should have spacing
if ( afterOpen && openParen.range[1] === afterOpen.range[0] ) {
context.report({
+1 -1
View File
@@ -47,7 +47,7 @@ const whoami_common = ({ is_user, user }) => {
epoch = new Date(user.last_activity_ts).getTime();
// round to 1 decimal place
epoch = Math.round(epoch / 1000);
} catch(e) {
} catch (e) {
console.error('Error parsing last_activity_ts', e);
}