Skip to content

Commit

Permalink
chore: use shared prettier config (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Oct 13, 2019
1 parent a8dfa9e commit 02438dc
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 39 deletions.
16 changes: 9 additions & 7 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
extends:
- eslint:recommended
- plugin:jest/recommended
- plugin:prettier/recommended
- eslint:recommended
- plugin:jest/recommended
- plugin:prettier/recommended
env:
es6: true
node: true
parserOptions:
ecmaVersion: 2019
rules:
no-console: off
no-console: 0
overrides:
- files: "src/**/*.js"
parserOptions:
sourceType: module
- files: 'src/**/*.js'
parserOptions:
sourceType: module
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierrc.yml

This file was deleted.

14 changes: 7 additions & 7 deletions bin/pretty-quick.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const prettyQuickResult = prettyQuick(
onFoundSinceRevision: (scm, revision) => {
console.log(
`🔍 Finding changed files since ${chalk.bold(
scm
)} revision ${chalk.bold(revision)}.`
scm,
)} revision ${chalk.bold(revision)}.`,
);
},

onFoundChangedFiles: changedFiles => {
console.log(
`🎯 Found ${chalk.bold(changedFiles.length)} changed ${
changedFiles.length === 1 ? 'file' : 'files'
}.`
}.`,
);
},

Expand All @@ -45,7 +45,7 @@ const prettyQuickResult = prettyQuick(
onExamineFile: file => {
console.log(`🔍 Examining ${chalk.bold(file)}.`);
},
})
}),
);

if (prettyQuickResult.success) {
Expand All @@ -54,17 +54,17 @@ if (prettyQuickResult.success) {
if (prettyQuickResult.errors.indexOf('PARTIALLY_STAGED_FILE') !== -1) {
console.log(
'✗ Partially staged files were fixed up.' +
` ${chalk.bold('Please update stage before committing')}.`
` ${chalk.bold('Please update stage before committing')}.`,
);
}
if (prettyQuickResult.errors.indexOf('BAIL_ON_WRITE') !== -1) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.'
'✗ File had to be prettified and prettyQuick was set to bail mode.',
);
}
if (prettyQuickResult.errors.indexOf('CHECK_FAILED') !== -1) {
console.log(
'✗ Code style issues found in the above file(s). Forgot to run Prettier?'
'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
);
}
process.exit(1); // ensure git hooks abort
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
"hooks": {
"pre-commit": "./bin/pretty-quick.js --staged"
}
},
},
"prettier": "@azz/prettier-config",
"peerDependencies": {
"prettier": ">=1.8.0"
},
"devDependencies": {
"@azz/prettier-config": "^1.0.0",
"@babel/cli": "^7.6 .4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/pretty-quick.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ test('throws an error when no vcs is found', () => {
});

expect(() => prettyQuick('root')).toThrow(
'Unable to detect a source control manager.'
'Unable to detect a source control manager.',
);
});
14 changes: 7 additions & 7 deletions src/__tests__/scm-git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const mockGitFs = (additionalUnstaged = '', additionalFiles = {}) => {
'/foo.js': 'foo()',
'/bar.md': '# foo',
},
additionalFiles
)
additionalFiles,
),
);
execa.sync.mockImplementation((command, args) => {
if (command !== 'git') {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('with git', () => {
expect(execa.sync).toHaveBeenCalledWith(
'git',
['merge-base', 'HEAD', 'master'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand All @@ -68,7 +68,7 @@ describe('with git', () => {
expect(execa.sync).toHaveBeenCalledWith(
'git',
['merge-base', 'HEAD', 'master'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand Down Expand Up @@ -96,7 +96,7 @@ describe('with git', () => {
expect(execa.sync).toHaveBeenCalledWith(
'git',
['diff', '--name-only', '--diff-filter=ACMRTUB'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand All @@ -110,7 +110,7 @@ describe('with git', () => {
expect(execa.sync).toHaveBeenCalledWith(
'git',
['diff', '--name-only', '--diff-filter=ACMRTUB', 'banana'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand All @@ -124,7 +124,7 @@ describe('with git', () => {
expect(execa.sync).toHaveBeenCalledWith(
'git',
['ls-files', '--others', '--exclude-standard'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/scm-hg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const mockHgFs = (additionalFiles = {}) => {
'/foo.js': 'foo()',
'/bar.md': '# foo',
},
additionalFiles
)
additionalFiles,
),
);
execa.sync.mockImplementation((command, args) => {
if (command !== 'hg') {
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('with hg', () => {
expect(execa.sync).toHaveBeenCalledWith(
'hg',
['debugancestor', 'tip', 'default'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand All @@ -66,7 +66,7 @@ describe('with hg', () => {
expect(execa.sync).toHaveBeenCalledWith(
'hg',
['debugancestor', 'tip', 'default'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand All @@ -80,7 +80,7 @@ describe('with hg', () => {
expect(execa.sync).toHaveBeenCalledWith(
'hg',
['status', '-n', '-a', '-m', '--rev', 'banana'],
{ cwd: '/' }
{ cwd: '/' },
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default (
onExamineFile,
onCheckFile,
onWriteFile,
} = {}
} = {},
) => {
const scm = scms(currentDirectory);
if (!scm) {
Expand Down
2 changes: 1 addition & 1 deletion src/isSupportedExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getSupportInfo } from 'prettier';

const extensions = getSupportInfo().languages.reduce(
(prev, language) => prev.concat(language.extensions || []),
[]
[],
);

export default file => extensions.includes(extname(file));
4 changes: 2 additions & 2 deletions src/processFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join } from 'path';
export default (
directory,
files,
{ check, config, onExamineFile, onCheckFile, onWriteFile } = {}
{ check, config, onExamineFile, onCheckFile, onWriteFile } = {},
) => {
for (const relative of files) {
onExamineFile && onExamineFile(relative);
Expand All @@ -16,7 +16,7 @@ export default (
config,
editorconfig: true,
}),
{ filepath: file }
{ filepath: file },
);
const input = readFileSync(file, 'utf8');

Expand Down
6 changes: 3 additions & 3 deletions src/scms/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export const getChangedFiles = (directory, revision, staged) => {
staged ? '--cached' : null,
'--diff-filter=ACMRTUB',
revision,
].filter(Boolean)
)
].filter(Boolean),
),
),
...(staged
? []
: getLines(
runGit(directory, ['ls-files', '--others', '--exclude-standard'])
runGit(directory, ['ls-files', '--others', '--exclude-standard']),
)),
].filter(Boolean);
};
Expand Down
2 changes: 1 addition & 1 deletion src/scms/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getSinceRevision = (directory, { branch }) => {
export const getChangedFiles = (directory, revision) => {
return [
...getLines(
runHg(directory, ['status', '-n', '-a', '-m', '--rev', revision])
runHg(directory, ['status', '-n', '-a', '-m', '--rev', revision]),
),
].filter(Boolean);
};
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@azz/prettier-config@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@azz/prettier-config/-/prettier-config-1.0.0.tgz#ecd38a9e4152fbd03043e020ee73cd14c0e3c112"
integrity sha512-2R3F5XWq8YoBXEbqjlraRt8c6Z8GnV4X/gOw0kAi9dn5aCCFHqqDuprQD0UBds4heH6tRp6ZGSeXyG6YZJUgAQ==

"@babel/cli@^7.6 .4":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.6.4.tgz#9b35a4e15fa7d8f487418aaa8229c8b0bc815f20"
Expand Down

0 comments on commit 02438dc

Please sign in to comment.