Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class PHPCSFixer extends PHPCSFixerConfig {
return args
}

format(text: string | Buffer, uri: Uri, isDiff: boolean = false, isPartial: boolean = false): Promise<string> {
format(text: string | Buffer, uri: Uri, isDiff: boolean = false, isPartial: boolean = false): Promise<string | null> {
isRunning = true
clearOutput()
isPartial || statusInfo('formatting')
Expand Down Expand Up @@ -226,8 +226,12 @@ class PHPCSFixer extends PHPCSFixerConfig {
resolve(filePath)
} else {
let result = JSON.parse(stdout)
if (result && result.files.length > 0) {
resolve(fs.readFileSync(filePath, 'utf-8'))
if (result && result.files) {
if (result.files.length > 0) {
resolve(fs.readFileSync(filePath, 'utf-8'))
} else {
resolve(null) // no changes
}
} else {
let lines = stderr.split(/\r?\n/).filter(Boolean)
if (lines.length > 1) {
Expand Down Expand Up @@ -374,6 +378,9 @@ class PHPCSFixer extends PHPCSFixerConfig {

this.format(originalText, document.uri, false, true)
.then((text) => {
if (text == null) {
return // no changes
}
text = dealFun(text)
if (text != dealFun(originalText)) {
editor
Expand Down Expand Up @@ -418,6 +425,9 @@ class PHPCSFixer extends PHPCSFixerConfig {

this.format(originalText, editor.document.uri, false, true)
.then((text) => {
if (text == null) {
return // no changes
}
text = dealFun(text)
if (text != dealFun(originalText)) {
text = indent + text
Expand Down Expand Up @@ -495,6 +505,9 @@ class PHPCSFixer extends PHPCSFixerConfig {

this.format(originalText, document.uri)
.then((text) => {
if (text == null) {
return resolve([]) // no changes
}
if (addPHPTag) {
text = text.replace(/^<\?php\r?\n/, '')
}
Expand Down