Skip to content

Commit

Permalink
Prettier1.14 fix (prettier#544)
Browse files Browse the repository at this point in the history
fix prettier#543 eslint integration
fix range formatter
update prettier to 1.14.2
  • Loading branch information
CiGit authored Aug 9, 2018
1 parent 4c1bc44 commit e589622
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 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
Expand Up @@ -200,7 +200,7 @@
},
"dependencies": {
"ignore": "^3.3.8",
"prettier": "1.14.0",
"prettier": "1.14.2",
"prettier-eslint": "^8.8.1",
"prettier-stylelint": "^0.4.2",
"prettier-tslint": "^0.4.0",
Expand Down
15 changes: 10 additions & 5 deletions src/PrettierEditProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'vscode';

import { safeExecution, addToOutput, setUsedModule } from './errorHandler';
import { getGroup, getParsersFromLanguageId, getConfig } from './utils';
import { getParsersFromLanguageId, getConfig } from './utils';
import { requireLocalPkg } from './requirePkg';

import {
Expand Down Expand Up @@ -125,9 +125,13 @@ async function format(
} else {
parser = dynamicParsers[0];
}
const doesParserSupportEslint = getGroup('JavaScript').some(lang =>
lang.parsers.includes(parser)
);
const doesParserSupportEslint = [
'javascript',
'javascriptreact',
'typescript',
'typescriptreact',
'vue',
].includes(languageId);

const hasConfig = await hasPrettierConfig(fileName);

Expand Down Expand Up @@ -167,7 +171,8 @@ async function format(
if (vscodeConfig.tslintIntegration && parser === 'typescript') {
return safeExecution(
() => {
const prettierTslint = require('prettier-tslint').format as PrettierTslintFormat;
const prettierTslint = require('prettier-tslint')
.format as PrettierTslintFormat;
setUsedModule('prettier-tslint', 'Unknown', true);

return prettierTslint({
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'vscode';
import EditProvider from './PrettierEditProvider';
import { setupErrorHandler, registerDisposables } from './errorHandler';
import { allEnabledLanguages, allJSLanguages, getConfig } from './utils';
import { allEnabledLanguages, rangeSupportedLanguages, getConfig } from './utils';
import configFileListener from './configCacheHandler';
import ignoreFileHandler from './ignoreFileHandler';

Expand Down Expand Up @@ -37,7 +37,7 @@ function disposeHandlers() {
*/
function selectors(): Selectors {
const allLanguages = allEnabledLanguages();
const allRangeLanguages = allJSLanguages();
const allRangeLanguages = rangeSupportedLanguages();
const { disableLanguages } = getConfig();
const globalLanguageSelector = allLanguages.filter(
l => !disableLanguages.includes(l)
Expand Down
16 changes: 9 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export function allEnabledLanguages(): string[] {
);
}

export function allJSLanguages(): string[] {
return getGroup('JavaScript')
.filter(language => language.group === 'JavaScript')
.reduce(
(ids, language) => [...ids, ...(language.vscodeLanguageIds || [])],
[] as string[]
);
export function rangeSupportedLanguages(): string[] {
return [
'javascript',
'javascriptreact',
'typescript',
'typescriptreact',
'json',
'graphql',
];
}

export function getGroup(group: string): PrettierSupportInfo['languages'] {
Expand Down

0 comments on commit e589622

Please sign in to comment.