Skip to content

Commit

Permalink
chore: Add prettier (#52)
Browse files Browse the repository at this point in the history
add prettier
---------

Co-authored-by: wuxiuran <[email protected]>
  • Loading branch information
wuxiuran and wuxiuran authored Jun 1, 2023
1 parent 9c4a723 commit 7afc31d
Show file tree
Hide file tree
Showing 274 changed files with 4,159 additions and 2,887 deletions.
41 changes: 12 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ module.exports = {
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'prettier',
],
plugins: [
'@zaihui/eslint-plugin-react',
],
plugins: ['@zaihui/eslint-plugin-react'],
env: {
node: false,
browser: false,
Expand Down Expand Up @@ -99,7 +98,8 @@ module.exports = {
},
],
'@typescript-eslint/member-delimiter-style': [
'error', {
'error',
{
multiline: {
delimiter: 'none',
requireLast: false,
Expand All @@ -111,9 +111,7 @@ module.exports = {
},
],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-empty-function': [
'warn',
],
'@typescript-eslint/no-empty-function': ['warn'],
'@typescript-eslint/type-annotation-spacing': [
'error',
{
Expand All @@ -131,10 +129,7 @@ module.exports = {
},
overrides: [
{
files: [
'**/*.js',
'**/.*.js',
],
files: ['**/*.js', '**/.*.js'],
parser: 'esprima',
env: {
node: true,
Expand All @@ -146,9 +141,7 @@ module.exports = {
},
},
{
files: [
'**/*.tsx',
],
files: ['**/*.tsx'],
rules: {
/**
* taro的枚举条件渲染写法中对象的属性一定要用引号包裹,否则运行时会报错
Expand All @@ -160,11 +153,7 @@ module.exports = {
},
},
{
files: [
'test/**/*.ts',
'test/**/*.tsx',
'test/**/*.js',
],
files: ['test/**/*.ts', 'test/**/*.tsx', 'test/**/*.js'],
env: {
jest: true,
},
Expand All @@ -180,9 +169,7 @@ module.exports = {
* 开启了这里的extends会报Unexpected top-level property "overrides[2].extends".
* 怀疑是vscode下eslint插件的报错,待研究
*/
extends: [
'plugin:jest/all',
],
extends: ['plugin:jest/all'],
rules: {
'jest/prefer-inline-snapshots': 'off',
'jest/prefer-called-with': 'off',
Expand All @@ -193,16 +180,14 @@ module.exports = {
* 针对vuepress下的lint规则
*/
{
files: [
'docs/.vuepress/**/*.js',
'docs/.vuepress/**/*.vue',
],
files: ['docs/.vuepress/**/*.js', 'docs/.vuepress/**/*.vue'],
extends: [
'airbnb-base',
'@zaihui/base',
'plugin:vue/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'prettier',
],
env: {
node: true,
Expand All @@ -217,9 +202,7 @@ module.exports = {
* 允许src/pages下使用@作为alias以方便demo编写
*/
{
files: [
'src/pages/**/*.*',
],
files: ['src/pages/**/*.*'],
settings: {
'import/resolver': {
typescript: {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
branches:
- main
- dev
- open-source # test
- open-source # test

permissions:
contents: read # to fetch code (actions/checkout)
Expand All @@ -28,8 +28,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with :
ref : ${{ github.ref || github.head_ref || github.ref_name }}
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx pretty-quick --staged
npx lint-staged
3 changes: 3 additions & 0 deletions .perttier/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

find src \( -name "*.ts" -o -name "*.tsx" -o -name "*.scss" \) -print0 | xargs -0 -I {} sh -c 'prettier --write "{}" 2>/dev/null || true'
23 changes: 23 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"singleQuote": true,
"bracketSpacing": true,
"jsxSingleQuote": true,
"bracketSameLine": false,
"trailingComma": "all",
"trailingZero": "none",
"printWidth": 80,
"arrowParens": "always",
"semi": false,
"proseWrap": "never",
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
],
"rule": {
"number-leading-zero": "never"
}
}
4 changes: 2 additions & 2 deletions .versionrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

const { homepage: repositoriesUrl } = require('./package.json')

const getUrlFormat = hash => `${repositoriesUrl}${hash}`
const getUrlFormat = (hash) => `${repositoriesUrl}${hash}`

module.exports = {
header: '# CHANGELOG',
releaseCommitMessageFormat: 'chore(release): {{currentTag}}',
commitUrlFormat: getUrlFormat('/commit/{{hash}}'),
compareUrlFormat: getUrlFormat(`/compare/{{previousTag}}...{{currentTag}}`)
compareUrlFormat: getUrlFormat(`/compare/{{previousTag}}...{{currentTag}}`),
}
3 changes: 1 addition & 2 deletions config/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module.exports = {
env: {
NODE_ENV: '"production"',
},
defineConstants: {
},
defineConstants: {},
mini: {},
h5: {
/**
Expand Down
3 changes: 1 addition & 2 deletions config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module.exports = {
env: {
NODE_ENV: '"development"',
},
defineConstants: {
},
defineConstants: {},
mini: {},
h5: {
publicPath: '/',
Expand Down
58 changes: 30 additions & 28 deletions config/dist/index.dev.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";
'use strict'

var path = require('path');
var path = require('path')

var devConfig = require('./dev');
var devConfig = require('./dev')

var alphaConfig = require('./alpha');
var alphaConfig = require('./alpha')

var prodConfig = require('./prod');
var prodConfig = require('./prod')

var config = {
projectName: 'example',
Expand All @@ -17,71 +17,73 @@ var config = {
375: 2 / 1,
640: 2.34 / 2,
750: 1,
828: 1.81 / 2
828: 1.81 / 2,
},
sourceRoot: 'src',
outputRoot: 'dist',
defineConstants: {},
alias: {
'@': path.resolve(__dirname, '../src/')
'@': path.resolve(__dirname, '../src/'),
},
mini: {
postcss: {
autoprefixer: {
enable: true,
config: {}
config: {},
},
pxtransform: {
enable: true,
config: {}
config: {},
},
url: {
enable: true,
config: {
limit: 10240 // 设定转换尺寸上限

}
limit: 10240, // 设定转换尺寸上限
},
},
cssModules: {
enable: false,
// 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module',
// 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
},
h5: {
publicPath: '/',
staticDirectory: 'static',
postcss: {
autoprefixer: {
enable: true,
config: {}
config: {},
},
cssModules: {
enable: false,
// 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module',
// 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
}
};
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
},
},
}

module.exports = function (merge) {
var getEnvConfig = function getEnvConfig(environment) {
if (environment === 'prod') {
return prodConfig;
return prodConfig
}

return alphaConfig;
};
return alphaConfig
}

return merge(config, process.env.NODE_ENV === 'development' ? devConfig : getEnvConfig(process.env.BUILD_ENV));
};
return merge(
config,
process.env.NODE_ENV === 'development' ? devConfig : getEnvConfig(process.env.BUILD_ENV),
)
}
9 changes: 3 additions & 6 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const config = {
},
sourceRoot: 'src',
outputRoot: 'dist',
defineConstants: {
},
defineConstants: {},
alias: {
'@': path.resolve(__dirname, '../src/'),
},
Expand All @@ -30,9 +29,7 @@ const config = {
},
pxtransform: {
enable: true,
config: {

},
config: {},
},
url: {
enable: true,
Expand Down Expand Up @@ -72,7 +69,7 @@ const config = {
}

module.exports = function (merge) {
const getEnvConfig = environment => {
const getEnvConfig = (environment) => {
if (environment === 'prod') {
return prodConfig
}
Expand Down
3 changes: 1 addition & 2 deletions config/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module.exports = {
env: {
NODE_ENV: '"production"',
},
defineConstants: {
},
defineConstants: {},
mini: {},
h5: {
/**
Expand Down
Loading

0 comments on commit 7afc31d

Please sign in to comment.