Skip to content

Commit

Permalink
2024.02.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lovedder1995 committed Feb 8, 2024
1 parent 4cc4807 commit 3233be0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 66 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions rules/assignments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const matchMultilineString = require('../lib/match_multiline_string.js')
const ignoreStrings = require('../lib/ignore_strings.js')
const arrayForEach = require('../lib/array_for_each.js')
const arrayPipe = require('../lib/array_pipe.js')
const arrayCompose = require('../lib/array_compose.js')

module.exports = ({ lines, filename }) => {
const indentation = [
Expand Down Expand Up @@ -92,7 +92,7 @@ module.exports = ({ lines, filename }) => {

let assignmentBadSpacing = false

arrayPipe([
arrayCompose([
{
line: lines[index],
transform: line => {
Expand Down Expand Up @@ -169,7 +169,7 @@ module.exports = ({ lines, filename }) => {
array: assignmentsReplacements,
iteration: element => {
const [assignment, replacement] = element
lines[index] = arrayPipe([
lines[index] = arrayCompose([
{
line: lines[index],
transform: line => {
Expand Down
127 changes: 69 additions & 58 deletions rules/closures.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,77 +77,88 @@ module.exports = ({ lines, filename }) => {
if (!closureDeclaration.line) {
const matchedClosureDeclaration = matchClosures({ indentationLevel, lines, index, filename })

if (matchedClosureDeclaration) {
if (matchedClosureDeclaration.error) {
if (!matchedClosureDeclaration) {
return true
}

if (matchedClosureDeclaration.error) {
return false
}

const linesBefore = [
lines[index - 1],
lines[index - 2]
]

const firstLine = linesBefore[0] === undefined
if (!firstLine) {
if ((!linesBefore[0].trimStart().startsWith('}') && linesBefore[0] !== '') || linesBefore[1] === '') {
console.log(`${filename} ${index + 1}`, '- There must be one blank line before each closure')
return false
}
}

const linesBefore = [
lines[index - 1],
lines[index - 2]
]
closureDeclaration = matchedClosureDeclaration

if (linesBefore[0] !== undefined) {
if ((!linesBefore[0].trimStart().startsWith('}') && linesBefore[0] !== '') || linesBefore[1] === '') {
console.log(`${filename} ${index + 1}`, '- There must be one blank line before each closure')
return false
}
return true
}

if (lines[index] === '') {
const lastLine = lines.length - 1 === index
const topLevelClosure = indentationLevel === ''

if (topLevelClosure) {
if (lastLine) {
lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index] = '}'
lines[index + 1] = ''
}

closureDeclaration = matchedClosureDeclaration
return true
}
} else {
if (lines[index] === '') {
const lastLine = lines.length - 1 === index
const topLevelClosure = indentationLevel === ''

if (topLevelClosure) {
if (lastLine) {
lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index] = '}'
lines[index + 1] = ''
}
} else {
const remainingExpressionsInTheScope = !lastLine && lines[index + 1].startsWith(`${indentationLevel} `)
if (remainingExpressionsInTheScope) {
return true
}

lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index] = `${indentationLevel}}`
closureDeclaration = {}
}
} else {
const topLevelDeclaration = !lines[index].startsWith(' ')
if (topLevelDeclaration) {
const linesBefore = [
lines[index - 1],
lines[index - 2],
lines[index - 3]
]

const twoBlankLines = linesBefore[0] === '' && linesBefore[1] === '' && linesBefore[2] !== ''

if (!twoBlankLines) {
console.log(`${filename} ${index + 1}`, '- There must be two blank lines before each top level closure')
return false
}
const remainingExpressionsInTheScope = !lastLine && lines[index + 1].startsWith(`${indentationLevel} `)
if (remainingExpressionsInTheScope) {
return true
}

lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index - 2] = '}'
closureDeclaration = {}
lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index] = `${indentationLevel}}`
closureDeclaration = {}

return true
}

const matchedClosureDeclaration = matchClosures({ indentationLevel, lines, index, filename })
const topLevelDeclaration = !lines[index].startsWith(' ')
if (topLevelDeclaration) {
const linesBefore = [
lines[index - 1],
lines[index - 2],
lines[index - 3]
]

if (matchedClosureDeclaration) {
if (matchedClosureDeclaration.error) {
return false
}
closureDeclaration = matchedClosureDeclaration
}
}
const twoBlankLines = linesBefore[0] === '' && linesBefore[1] === '' && linesBefore[2] !== ''

if (!twoBlankLines) {
console.log(`${filename} ${index + 1}`, '- There must be two blank lines before each top level closure')
return false
}

lines[closureDeclaration.index] = `${closureDeclaration.line} {`
lines[index - 2] = '}'
closureDeclaration = {}

const matchedClosureDeclaration = matchClosures({ indentationLevel, lines, index, filename })

if (!matchedClosureDeclaration) {
return true
}

if (matchedClosureDeclaration.error) {
return false
}

closureDeclaration = matchedClosureDeclaration
}

return true
Expand Down
6 changes: 3 additions & 3 deletions rules/comparison_operators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const matchMultilineString = require('../lib/match_multiline_string.js')
const ignoreStrings = require('../lib/ignore_strings.js')
const arrayPipe = require('../lib/array_pipe.js')
const arrayCompose = require('../lib/array_compose.js')
const arrayForEach = require('../lib/array_for_each.js')

module.exports = ({ lines, filename }) => {
Expand All @@ -24,11 +24,11 @@ module.exports = ({ lines, filename }) => {
'is_greater_than_or_equal_to ': '>= '
}

arrayPipe([
arrayCompose([
{
array: Object.keys(operatorsReplacements),
iteration: operator => {
lines[index] = arrayPipe([
lines[index] = arrayCompose([
{
line: lines[index],
transform: line => line.replaceAll(operator, operatorsReplacements[operator])
Expand Down
4 changes: 2 additions & 2 deletions rules/strings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const matchMultilineString = require('../lib/match_multiline_string.js')
const arrayPipe = require('../lib/array_pipe.js')
const arrayCompose = require('../lib/array_compose.js')
const ignoreStrings = require('../lib/ignore_strings.js')

module.exports = ({ lines, filename }) => {
Expand All @@ -16,7 +16,7 @@ module.exports = ({ lines, filename }) => {

let badStringAssignment = false

arrayPipe([
arrayCompose([
{
line: lines[index],
transform: line => {
Expand Down

0 comments on commit 3233be0

Please sign in to comment.