Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
pro-blocks
Commits
7b77a0d7
Commit
7b77a0d7
authored
Dec 01, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prettier lint
parent
e9e8775e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
5 deletions
+49
-5
package.json
package.json
+2
-2
scripts/lint-prettier.js
scripts/lint-prettier.js
+43
-0
scripts/prettier.js
scripts/prettier.js
+4
-3
No files found.
package.json
View file @
7b77a0d7
...
...
@@ -20,7 +20,7 @@
"test"
:
"umi test"
,
"test:component"
:
"umi test ./src/components"
,
"test:all"
:
"node ./tests/run-tests.js"
,
"prettier"
:
"node
node
./scripts/prettier.js"
,
"prettier"
:
"node ./scripts/prettier.js"
,
"docker:dev"
:
"docker-compose -f ./docker/docker-compose.dev.yml up"
,
"docker:build"
:
"docker-compose -f ./docker/docker-compose.dev.yml build"
,
"docker-prod:dev"
:
"docker-compose -f ./docker/docker-compose.yml up"
,
...
...
@@ -100,7 +100,7 @@
},
"lint-staged"
:
{
"**/*.{js,jsx,less}"
:
[
"
prettier --write
"
,
"
node ./scripts/lint-prettier.js
"
,
"git add"
],
"**/*.{js,jsx}"
:
"npm run lint-staged:js"
,
...
...
scripts/lint-prettier.js
0 → 100644
View file @
7b77a0d7
/**
* copy to https://github.com/facebook/react/blob/master/scripts/prettier/index.js
* prettier api doc https://prettier.io/docs/en/api.html
*----------*****--------------
* lint file is prettier
*----------*****--------------
*/
const
glob
=
require
(
'
glob
'
);
const
prettier
=
require
(
'
prettier
'
);
const
fs
=
require
(
'
fs
'
);
const
prettierConfigPath
=
require
.
resolve
(
'
../.prettierrc
'
);
const
files
=
process
.
argv
.
slice
(
2
);
let
didError
=
false
;
let
didWarn
=
false
;
files
.
forEach
(
file
=>
{
const
options
=
prettier
.
resolveConfig
.
sync
(
file
,
{
config
:
prettierConfigPath
,
});
try
{
const
fileInfo
=
prettier
.
getFileInfo
.
sync
(
file
);
const
input
=
fs
.
readFileSync
(
file
,
'
utf8
'
);
const
withParserOptions
=
{
...
options
,
parser
:
fileInfo
.
inferredParser
,
};
const
isPrettier
=
prettier
.
check
(
input
,
withParserOptions
);
if
(
!
isPrettier
)
{
console
.
log
(
`\x1b[31m
${
file
}
is no prettier, please use npm run prettier and git add !`
);
didWarn
=
true
;
}
}
catch
(
e
)
{
didError
=
true
;
}
});
if
(
didWarn
||
didError
)
{
process
.
exit
(
1
);
}
console
.
log
(
'
\
x1b[32m lint prettier success!
'
);
scripts/prettier.js
View file @
7b77a0d7
...
...
@@ -22,11 +22,11 @@ if (!files.length) {
return
;
}
files
.
forEach
(
async
file
=>
{
files
.
forEach
(
file
=>
{
const
options
=
prettier
.
resolveConfig
.
sync
(
file
,
{
config
:
prettierConfigPath
,
});
const
fileInfo
=
await
prettier
.
getFileInfo
(
file
);
const
fileInfo
=
prettier
.
getFileInfo
.
sync
(
file
);
try
{
const
input
=
fs
.
readFileSync
(
file
,
'
utf8
'
);
const
withParserOptions
=
{
...
...
@@ -42,7 +42,8 @@ files.forEach(async file => {
didError
=
true
;
}
});
console
.
log
(
'
\
x1b[32m prettier success!
'
);
if
(
didError
)
{
process
.
exit
(
1
);
}
console
.
log
(
'
\
x1b[32m prettier success!
'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment