Skip to content

Commit

Permalink
2024.01.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lovedder1995 committed Jan 23, 2024
1 parent 5f734d0 commit 4cc4807
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "php-bundler",
"version": "2.1.0",
"version": "2024.01.1",
"main": "index.js",
"bin": "index.js",
"repository": {
Expand Down
17 changes: 12 additions & 5 deletions rules/closures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ const matchClosures = ({ indentationLevel, lines, index, filename }) => {

if (currentIndentationLevel && lines[index].endsWith('{')) {
console.log(`${filename} ${index + 1}`, '- Lines should not end with a opening curly bracket')
return false
return { error: true }
}

if (lines[index].includes('function ()') || lines[index].includes('function ( )')) {
console.log(`${filename} ${index + 1}`, '- Functions without parameters must not have parentheses.')
return false
return { error: true }
}

if (lines[index].includes('use ()') || lines[index].includes('use ( )')) {
if (lines[index].endsWith(' use') || lines[index].endsWith(' use ()') || lines[index].endsWith(' use ( )')) {
console.log(`${filename} ${index + 1}`, '- The keyword "use" in functions must not be used without arguments.')
return false
return { error: true }
}

if (currentIndentationLevel && lines[index].includes('function use')) {
lines[index] = lines[index].replace('function use', 'function () use')
}

if (currentIndentationLevel && lines[index].endsWith('function')) {
if (currentIndentationLevel && lines[index].endsWith(' function')) {
lines[index] = `${lines[index].slice(0, -8)}function ()`
}

Expand Down Expand Up @@ -78,6 +78,10 @@ module.exports = ({ lines, filename }) => {
const matchedClosureDeclaration = matchClosures({ indentationLevel, lines, index, filename })

if (matchedClosureDeclaration) {
if (matchedClosureDeclaration.error) {
return false
}

const linesBefore = [
lines[index - 1],
lines[index - 2]
Expand Down Expand Up @@ -137,6 +141,9 @@ module.exports = ({ lines, filename }) => {
const matchedClosureDeclaration = matchClosures({ indentationLevel, lines, index, filename })

if (matchedClosureDeclaration) {
if (matchedClosureDeclaration.error) {
return false
}
closureDeclaration = matchedClosureDeclaration
}
}
Expand Down

0 comments on commit 4cc4807

Please sign in to comment.