Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 3b3b57e

Browse files
committed
Initial commit
0 parents  commit 3b3b57e

14 files changed

+3712
-0
lines changed

.eslintrc.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"commonjs": true,
5+
"es6": true,
6+
"node": true
7+
},
8+
"parserOptions": {
9+
"ecmaFeatures": {
10+
"jsx": true
11+
},
12+
"sourceType": "module"
13+
},
14+
"rules": {
15+
"no-const-assign": "warn",
16+
"no-this-before-super": "warn",
17+
"no-undef": "warn",
18+
"no-unreachable": "warn",
19+
"no-unused-vars": "warn",
20+
"constructor-super": "warn",
21+
"valid-typeof": "warn"
22+
}
23+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.vscode-test/
3+
.vsix

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint"
6+
]
7+
}

.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// A launch configuration that launches the extension inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false
12+
},
13+
{
14+
"name": "Extension Tests",
15+
"type": "extensionHost",
16+
"request": "launch",
17+
"runtimeExecutable": "${execPath}",
18+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
19+
"stopOnEntry": false
20+
}
21+
]
22+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
}

.vscodeignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.vscode/**
2+
.vscode-test/**
3+
test/**
4+
.gitignore
5+
jsconfig.json
6+
vsc-extension-quickstart.md
7+
.eslintrc.json

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Change Log
2+
All notable changes to the "vscode-php-cs-fixer" extension will be documented in this file.
3+
4+
## 0.0.1
5+
- Initial release

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# vscode-php-cs-fixer
2+
3+
This extension adds support for running `php-cs-fixer fix` on PHP files in Visual Studio Code.
4+
5+
## Requirements
6+
7+
[php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
8+
9+
## Extension Settings
10+
11+
This extension contributes the following settings:
12+
13+
* `vscode-php-cs-fixer.toolPath`: The path to the php-cs-fixer tool
14+
* `vscode-php-cs-fixer.useCache`: Use a cache file when fixing files (--using-cache)
15+
* `vscode-php-cs-fixer.rules`: Rules to use when fixing files (--rules)
16+
* `vscode-php-cs-fixer.fixOnSave`: Runs fix command on save

extension.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const vscode = require('vscode');
2+
const path = require('path');
3+
const cp = require('child_process');
4+
5+
function fixDocument(document) {
6+
if (document.languageId !== 'php') {
7+
return;
8+
}
9+
10+
let toolPath = getConfig('toolPath');
11+
let filename = document.fileName;
12+
let args = ['fix'];
13+
let opts = { cwd: path.dirname(filename) };
14+
15+
if (!getConfig('useCache')) {
16+
args.push('--using-cache=no');
17+
}
18+
19+
let rules = getConfig('rules');
20+
if (rules) {
21+
args.push('--rules=' + rules);
22+
}
23+
24+
cp.execFile(toolPath, [...args, filename], opts, function (err) {
25+
if (err && err.code === 'ENOENT') {
26+
vscode.window.showErrorMessage('Unable to find the php-cs-fixer tool.');
27+
return;
28+
}
29+
30+
if (err) {
31+
vscode.window.showErrorMessage('There was an error while running php-cs-fixer. Check the Developer Tools console for more information.');
32+
33+
console.log(err);
34+
return;
35+
}
36+
37+
document.save();
38+
});
39+
}
40+
41+
function getConfig(key) {
42+
return vscode.workspace.getConfiguration('vscode-php-cs-fixer').get(key);
43+
}
44+
45+
function activate(context) {
46+
context.subscriptions.push(vscode.commands.registerTextEditorCommand('vscode-php-cs-fixer.fix', function (textEditor) {
47+
fixDocument(textEditor.document);
48+
}));
49+
50+
vscode.workspace.onDidSaveTextDocument(function (document) {
51+
if (!getConfig('fixOnSave')) {
52+
return;
53+
}
54+
55+
fixDocument(document);
56+
});
57+
}
58+
exports.activate = activate;
59+
60+
function deactivate() {
61+
}
62+
exports.deactivate = deactivate;

jsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"lib": [
6+
"es6"
7+
]
8+
},
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

0 commit comments

Comments
 (0)