@unix/eslint 1.1.0 → 1.1.1
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,6 +86,25 @@ const reportPadding = (
|
|
|
84
86
|
|
|
85
87
|
const isReturnStatement = node => node.type === 'ReturnStatement'
|
|
86
88
|
|
|
89
|
+
const lineCountFor = node => node.loc.end.line - node.loc.start.line + 1
|
|
90
|
+
|
|
91
|
+
const hasBlockBody = node => {
|
|
92
|
+
if (node.type === 'BlockStatement') return true
|
|
93
|
+
if (node.type === 'FunctionDeclaration') return true
|
|
94
|
+
if (node.type === 'SwitchStatement') return true
|
|
95
|
+
if (node.type === 'TryStatement') return true
|
|
96
|
+
if (node.type === 'IfStatement') {
|
|
97
|
+
if (hasBlockBody(node.consequent)) return true
|
|
98
|
+
|
|
99
|
+
return Boolean(node.alternate && hasBlockBody(node.alternate))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return node.body?.type === 'BlockStatement'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const isLongBlockStatement = node =>
|
|
106
|
+
hasBlockBody(node) && lineCountFor(node) >= LONG_BLOCK_MIN_LINES
|
|
107
|
+
|
|
87
108
|
const messageIdForStatementGap = (previousStatement, nextStatement) => {
|
|
88
109
|
if (isReturnStatement(previousStatement)) return 'unexpectedBlankLineAfterReturn'
|
|
89
110
|
if (isReturnStatement(nextStatement)) return 'tooManyBlankLinesBeforeReturn'
|
|
@@ -94,6 +115,8 @@ const messageIdForStatementGap = (previousStatement, nextStatement) => {
|
|
|
94
115
|
const maxBlankLinesForStatementGap = (previousStatement, nextStatement) => {
|
|
95
116
|
if (isReturnStatement(previousStatement)) return 0
|
|
96
117
|
if (isReturnStatement(nextStatement)) return 1
|
|
118
|
+
if (isLongBlockStatement(previousStatement)) return 1
|
|
119
|
+
if (isLongBlockStatement(nextStatement)) return 1
|
|
97
120
|
|
|
98
121
|
return 0
|
|
99
122
|
}
|