Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add prettier to keep a uniform format in our code (#1667)
* prettier added to keep a uniform format in our code

* prettier and tslint playing well together

* added prettier to the recommended extensions

* removing not needed editorconfig lines
  • Loading branch information
robertohuertasm committed Aug 2, 2018
1 parent 2373350 commit a4a9b61
Show file tree
Hide file tree
Showing 51 changed files with 8,113 additions and 4,149 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Expand Up @@ -15,7 +15,3 @@ insert_final_newline = false

[*.md]
trim_trailing_whitespace = false

# Due to vsce formatting it with 4 spaces no matter what we set here.
[package.json]
indent_size = 4
2 changes: 2 additions & 0 deletions .prettierignore
@@ -0,0 +1,2 @@
*.md
*.json
6 changes: 6 additions & 0 deletions .prettierrc
@@ -0,0 +1,6 @@
{
"parser": "typescript",
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Expand Up @@ -4,6 +4,7 @@
"recommendations": [
"eg2.tslint",
"EditorConfig.EditorConfig",
"DavidAnson.vscode-markdownlint"
"DavidAnson.vscode-markdownlint",
"esbenp.prettier-vscode"
]
}
96 changes: 72 additions & 24 deletions package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -225,6 +225,7 @@
}
},
"scripts": {
"precommit": "pretty-quick --staged",
"preinstall": "git submodule update --init --recursive",
"postinstall": "vscode-install",
"prebuild": "npm run lint && npm run test",
Expand All @@ -250,15 +251,17 @@
"@types/semver": "^5.5.0",
"@types/sinon": "^5.0.1",
"chai": "^4.1.2",
"examples-generator": "file:submodules/examples-generator",
"mocha": "^5.2.0",
"mockery": "^2.1.0",
"nyc": "^12.0.2",
"prettier": "^1.14.0",
"pretty-quick": "^1.6.0",
"rimraf": "^2.6.2",
"sinon": "^6.0.0",
"tslint": "^5.10.0",
"tslint": "^5.11.0",
"typescript": "^2.9.1",
"vscode": "^1.1.18",
"examples-generator": "file:submodules/examples-generator"
"vscode": "^1.1.18"
},
"dependencies": {
"lodash": "^4.17.10",
Expand Down
26 changes: 19 additions & 7 deletions src/cleanUp/index.ts
Expand Up @@ -21,7 +21,9 @@ export function getAppUserPath(dirPath: string): string {
let dataDir: string;
switch (process.platform) {
case 'darwin':
const isInsiders = existsSync(pathUnixJoin(process.env.VSCODE_CWD, 'code-insiders-portable-data'));
const isInsiders = existsSync(
pathUnixJoin(process.env.VSCODE_CWD, 'code-insiders-portable-data'),
);
dataDir = `code-${isInsiders ? 'insiders-' : ''}portable-data`;
break;
default:
Expand All @@ -30,7 +32,8 @@ export function getAppUserPath(dirPath: string): string {
}
return pathUnixJoin(process.env.VSCODE_CWD, dataDir);
};
const appPath = process.env.VSCODE_PORTABLE || vscodePortable() || getAppPath();
const appPath =
process.env.VSCODE_PORTABLE || vscodePortable() || getAppPath();
return pathUnixJoin(appPath, vscodeAppName, 'User');
}

Expand All @@ -50,28 +53,37 @@ export function resetThemeSetting(settings: {}): void {
export function cleanUpVSCodeSettings(): void {
const saveSettings = content => {
const settings = JSON.stringify(content, null, 4);
writeFile(settingsFilePath, settings, error => ErrorHandler.LogError(error));
writeFile(settingsFilePath, settings, error =>
ErrorHandler.LogError(error),
);
};
const cleanUpSettings = (error, content) => {
if (error) {
ErrorHandler.LogError(error, true);
return;
}
const settings = parseJSON(content);
if (!settings) { return; }
if (!settings) {
return;
}

removeVSIconsSettings(settings);

resetThemeSetting(settings);

saveSettings(settings);
};
const settingsFilePath = pathUnixJoin(getAppUserPath(__dirname), 'settings.json');
const settingsFilePath = pathUnixJoin(
getAppUserPath(__dirname),
'settings.json',
);
readFile(settingsFilePath, 'utf8', cleanUpSettings);
}

export function cleanUpVSIconsSettings(): void {
const extensionSettingsFilePath = pathUnixJoin(getAppUserPath(__dirname),
constants.extensionSettingsFilename);
const extensionSettingsFilePath = pathUnixJoin(
getAppUserPath(__dirname),
constants.extensionSettingsFilename,
);
unlink(extensionSettingsFilePath, error => ErrorHandler.LogError(error));
}
16 changes: 10 additions & 6 deletions src/commands/helper.ts
Expand Up @@ -5,19 +5,21 @@ const foldersRelatedPresets = [
models.PresetNames.foldersAllDefaultIcon,
];

const nonIconsRelatedPresets = [
models.PresetNames.hideExplorerArrows,
];
const nonIconsRelatedPresets = [models.PresetNames.hideExplorerArrows];

export function isFoldersRelated(presetName: models.PresetNames): boolean {
return foldersRelatedPresets.some(preset => preset === presetName);
}

export function isNonIconsRelatedPreset(presetName: models.PresetNames): boolean {
export function isNonIconsRelatedPreset(
presetName: models.PresetNames,
): boolean {
return nonIconsRelatedPresets.some(preset => preset === presetName);
}

export function getFunc(preset: string): (iconsJson: models.IIconSchema) => boolean {
export function getFunc(
preset: string,
): (iconsJson: models.IIconSchema) => boolean {
switch (preset) {
case 'hideFolders':
return (iconsJson: models.IIconSchema) =>
Expand All @@ -34,6 +36,8 @@ export function getFunc(preset: string): (iconsJson: models.IIconSchema) => bool

export function getIconName(preset: string): string {
const iconName = models.IconNames[preset];
if (!iconName) { throw new Error('Not Implemented'); }
if (!iconName) {
throw new Error('Not Implemented');
}
return iconName;
}

0 comments on commit a4a9b61

Please sign in to comment.