@unix/eslint 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  const lineBreakFor = sourceCode => (sourceCode.text.includes('\r\n') ? '\r\n' : '\n')
2
2
 
3
+ const LONG_BLOCK_MIN_LINES = 4
4
+
3
5
  const indentationFor = (sourceCode, token) => {
4
6
  const line = sourceCode.lines[token.loc.start.line - 1] ?? ''
5
7
 
@@ -84,16 +86,46 @@ const reportPadding = (
84
86
 
85
87
  const isReturnStatement = node => node.type === 'ReturnStatement'
86
88
 
89
+ const isCompactReturnIfStatement = node =>
90
+ node.type === 'IfStatement' &&
91
+ !node.alternate &&
92
+ isReturnStatement(node.consequent) &&
93
+ node.loc.start.line === node.consequent.loc.start.line
94
+
95
+ const isReturnLikeStatement = node =>
96
+ isReturnStatement(node) || isCompactReturnIfStatement(node)
97
+
98
+ const lineCountFor = node => node.loc.end.line - node.loc.start.line + 1
99
+
100
+ const hasBlockBody = node => {
101
+ if (node.type === 'BlockStatement') return true
102
+ if (node.type === 'FunctionDeclaration') return true
103
+ if (node.type === 'SwitchStatement') return true
104
+ if (node.type === 'TryStatement') return true
105
+ if (node.type === 'IfStatement') {
106
+ if (hasBlockBody(node.consequent)) return true
107
+
108
+ return Boolean(node.alternate && hasBlockBody(node.alternate))
109
+ }
110
+
111
+ return node.body?.type === 'BlockStatement'
112
+ }
113
+
114
+ const isLongBlockStatement = node =>
115
+ hasBlockBody(node) && lineCountFor(node) >= LONG_BLOCK_MIN_LINES
116
+
87
117
  const messageIdForStatementGap = (previousStatement, nextStatement) => {
88
118
  if (isReturnStatement(previousStatement)) return 'unexpectedBlankLineAfterReturn'
89
- if (isReturnStatement(nextStatement)) return 'tooManyBlankLinesBeforeReturn'
119
+ if (isReturnLikeStatement(nextStatement)) return 'tooManyBlankLinesBeforeReturn'
90
120
 
91
121
  return 'unexpectedBlankLine'
92
122
  }
93
123
 
94
124
  const maxBlankLinesForStatementGap = (previousStatement, nextStatement) => {
95
125
  if (isReturnStatement(previousStatement)) return 0
96
- if (isReturnStatement(nextStatement)) return 1
126
+ if (isReturnLikeStatement(nextStatement)) return 1
127
+ if (isLongBlockStatement(previousStatement)) return 1
128
+ if (isLongBlockStatement(nextStatement)) return 1
97
129
 
98
130
  return 0
99
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unix/eslint",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "ESLint config for all @unix projects.",
5
5
  "type": "module",
6
6
  "main": "index.js",