Skip to content

Commit

Permalink
Some file format (prettier), new dep for phpfmt and fresh new ignore …
Browse files Browse the repository at this point in the history
…setting prop

- Prettier added to project to format and normalize JS/TS files;
- Fix the package dep for PHPFMT external project with a new package;
- Fresh new `ignore` setting prop to ignore auto format in some file extensions.
  • Loading branch information
lucasferreira committed Mar 28, 2023
1 parent d103197 commit e92644a
Show file tree
Hide file tree
Showing 17 changed files with 833 additions and 744 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
/out
/testProject
.vscode
.vscode-test
*.md
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ addons:

before_install:
- if [ $TRAVIS_OS_NAME == "linux" ]; then
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start;
sleep 3;
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start;
sleep 3;
fi
- nvm install 8;
- npm install -g yarn
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ A: Since phpfmt has no maintainers, only Serious bugs will be fixed.
| phpfmt.indent_with_space | `integer \| boolean` | use spaces instead of tabs for indentation. Default 4 | 4 |
| phpfmt.enable_auto_align | `boolean` | enable auto align of ST_EQUAL and T_DOUBLE_ARROW | false |
| phpfmt.visibility_order | `boolean` | fixes visibiliy order for method in classes - PSR-2 4.2 | false |
| phpfmt.ignore | `array` | ignore file names whose names contain any pattern that could be matched with `.match` JS string method | [] |
| phpfmt.passes | `array` | call specific compiler pass | [] |
| phpfmt.exclude | `array` | disable specific passes | [] |
| phpfmt.smart_linebreak_after_curly | `boolean` | convert multistatement blocks into multiline blocks | false |
Expand Down Expand Up @@ -146,6 +147,7 @@ transformation.
| PSR2MultilineFunctionParams | Break function parameters into multiple lines. |
| ReindentAndAlignObjOps | Align object operators. |
| ReindentSwitchBlocks | Reindent one level deeper the content of switch blocks. |
| ReindentEnumBlocks | Reindent one level deeper the content of enum blocks. |
| RemoveIncludeParentheses | Remove parentheses from include declarations. |
| RemoveSemicolonAfterCurly | Remove semicolon after closing curly brace. |
| RemoveUseLeadingSlash | Remove leading slash in T_USE imports. |
Expand All @@ -157,9 +159,7 @@ transformation.
| SmartLnAfterCurlyOpen | Add line break when implicit curly block is added. |
| SortUseNameSpace | Organize use clauses by length and alphabetic order. |
| SpaceAroundControlStructures | Add space around control structures. |
| SpaceAfterExclamationMark | Add space after exclamation mark. |
| SpaceAroundExclamationMark | Add spaces around exclamation mark. |
| SpaceAroundParentheses | Add spaces inside parentheses. |
| SpaceBetweenMethods | Put space between methods. |
| StrictBehavior | Activate strict option in array_search, base64_decode, in_array, array_keys, mb_detect_encoding. Danger! This pass leads to behavior change. |
| StrictComparison | All comparisons are converted to strict. Danger! This pass leads to behavior change. |
Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-phpfmt",
"displayName": "phpfmt - PHP formatter",
"version": "1.0.31",
"version": "1.0.32",
"description": "Integrates phpfmt into VS Code",
"main": "./out/src/extension",
"scripts": {
Expand All @@ -11,9 +11,9 @@
"trash": "trash out",
"generate": "ts-node scripts/generate.ts",
"postinstall": "node ./node_modules/vscode/bin/install",
"install": "node ./node_modules/phpfmt/install.js",
"pretest": "npm run build",
"test": "cross-env CODE_TESTS_WORKSPACE=testProject node ./node_modules/vscode/bin/test",
"format": "prettier --write .",
"prepublishOnly": "npm run build && vsce publish"
},
"keywords": [
Expand Down Expand Up @@ -106,6 +106,11 @@
"default": false,
"description": "fixes visibiliy order for method in classes - PSR-2 4.2"
},
"phpfmt.ignore": {
"type": "array",
"default": [],
"description": "ignore file names whose names contain any pattern that could be matched with `.match` JS string method"
},
"phpfmt.passes": {
"type": "array",
"default": [],
Expand Down Expand Up @@ -153,6 +158,6 @@
"dependencies": {
"detect-indent": "^6.0.0",
"find-up": "^5.0.0",
"phpfmt": "^0.0.0"
"use-phpfmt": "^0.0.1"
}
}
11 changes: 11 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
printWidth: 120,
singleQuote: false,
trailingComma: "es5",
bracketSpacing: true,
jsxBracketSameLine: true,
semi: true,
requirePragma: false,
proseWrap: "preserve",
arrowParens: "avoid",
};
94 changes: 38 additions & 56 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,66 @@
import path from 'path';
import fs from 'fs';
import os from 'os';
import Transformations from '../src/Transformations';
import path from "path";
import fs from "fs";
import os from "os";
import Transformations from "../src/Transformations";

const pkg: any = require('pjson');
const pkg: any = require("pjson");

const readmePath: string = path.join(__dirname, '/../README.md');
const readmePath: string = path.join(__dirname, "/../README.md");

const configuration: any = pkg.contributes.configuration;

let config: string =
'| Key | Type | Description | Default |' +
os.EOL +
'| -------- | ----------- | ----------- | ----------- |' +
os.EOL;
"| Key | Type | Description | Default |" + os.EOL + "| -------- | ----------- | ----------- | ----------- |" + os.EOL;

for (const configKey of Object.keys(configuration.properties)) {
const configValue = configuration.properties[configKey];
config += `| ${configKey} | `;

if (typeof configValue.type === 'string') {
if (typeof configValue.type === "string") {
config += `\`${configValue.type}\``;
} else if (Array.isArray(configValue.type)) {
config += `\`${configValue.type.join(' \\| ')}\``;
config += `\`${configValue.type.join(" \\| ")}\``;
}
config += ` | ${configValue.description}`;

if (typeof configValue.default === 'string') {
if (typeof configValue.default === "string") {
config += ` | "${configValue.default}"`;
} else if (typeof configValue.default === 'number') {
} else if (typeof configValue.default === "number") {
config += ` | ${configValue.default}`;
} else if (
Array.isArray(configValue.default) ||
typeof configValue.default === 'boolean'
) {
} else if (Array.isArray(configValue.default) || typeof configValue.default === "boolean") {
config += ` | ${JSON.stringify(configValue.default)}`;
} else {
throw new Error('uncovered type');
throw new Error("uncovered type");
}

config += ' | ' + os.EOL;
config += " | " + os.EOL;
}

let readmeContent = fs.readFileSync(readmePath).toString();
readmeContent = readmeContent.replace(
/<!-- Configuration START -->([\s\S]*)<!-- Configuration END -->/,
() => {
return (
'<!-- Configuration START -->' +
os.EOL +
config +
os.EOL +
'<!-- Configuration END -->'
);
}
);
readmeContent = readmeContent.replace(/<!-- Configuration START -->([\s\S]*)<!-- Configuration END -->/, () => {
return "<!-- Configuration START -->" + os.EOL + config + os.EOL + "<!-- Configuration END -->";
});

readmeContent = readmeContent.replace(
/<!-- Transformations START -->([\s\S]*)<!-- Transformations END -->/,
() => {
return (
'<!-- Transformations START -->' +
os.EOL +
'| Key | Description |' +
os.EOL +
'| -------- | ----------- |' +
os.EOL +
new Transformations('php')
.getTransformations()
.map(item => {
let row = `| ${item.key} | `;
row += item.description;
row += ' |';
return row;
})
.join(os.EOL) +
os.EOL +
'<!-- Transformations END -->'
);
}
);
readmeContent = readmeContent.replace(/<!-- Transformations START -->([\s\S]*)<!-- Transformations END -->/, () => {
return (
"<!-- Transformations START -->" +
os.EOL +
"| Key | Description |" +
os.EOL +
"| -------- | ----------- |" +
os.EOL +
new Transformations("php")
.getTransformations()
.map(item => {
let row = `| ${item.key} | `;
row += item.description;
row += " |";
return row;
})
.join(os.EOL) +
os.EOL +
"<!-- Transformations END -->"
);
});

fs.writeFileSync(readmePath, readmeContent);
3 changes: 2 additions & 1 deletion src/IPHPFmtConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export default interface IPHPFmtConfig {
indent_with_space: number | boolean;
enable_auto_align: boolean;
visibility_order: boolean;
ignore: Array<string>;
passes: Array<string>;
exclude: Array<string>;
smart_linebreak_after_curly: boolean;
yoda: boolean;
cakephp: boolean;
custom_arguments: string;
};
}
Loading

0 comments on commit e92644a

Please sign in to comment.