Skip to content

Commit

Permalink
Fix Prettier Commit Hook (#9245)
Browse files Browse the repository at this point in the history
* Apply format to webpack config

* hit all files
  • Loading branch information
Timer authored and timneutkens committed Oct 30, 2019
1 parent 636be24 commit 6b54e9e
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 183 deletions.
14 changes: 12 additions & 2 deletions examples/with-netlify-cms/public/static/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ collections:
slug: '{{year}}-{{month}}-{{day}}_{{slug}}'
fields:
- { label: 'Title', name: 'title', widget: 'string', required: true }
- { label: 'Publish Date', name: 'date', widget: 'datetime', required: true }
- { label: 'Featured Image', name: 'thumbnail', widget: 'image', required: true }
- {
label: 'Publish Date',
name: 'date',
widget: 'datetime',
required: true,
}
- {
label: 'Featured Image',
name: 'thumbnail',
widget: 'image',
required: true,
}
- { label: 'Body', name: 'body', widget: 'markdown', required: true }
4 changes: 3 additions & 1 deletion examples/with-next-offline/pages/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default () => <div>Next-Offline Example, try to install app via chrome</div>
export default () => (
<div>Next-Offline Example, try to install app via chrome</div>
)
2 changes: 1 addition & 1 deletion examples/with-next-offline/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"background_color": "#ffffff",
"start_url": "/",
"display": "standalone"
}
}
4 changes: 3 additions & 1 deletion examples/with-quill-js/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// next.config.js
const withCSS = require('@zeit/next-css')
module.exports = withCSS({/* my next config */})
module.exports = withCSS({
/* my next config */
})
3 changes: 3 additions & 0 deletions examples/with-tailwindcss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ now
## The idea behind the example

This setup is a basic starting point for using [Tailwind CSS](https://tailwindcss.com) with Next.js. This example also includes the following [PostCSS](https://github.com/postcss/postcss) plugins:

- [autoprefixer](https://github.com/postcss/autoprefixer) - Adds vendor prefixes to CSS rules in your stylesheet using values from [Can I Use](https://caniuse.com/)
- [purgecss](https://github.com/FullHuman/purgecss) - Removes unused CSS
- [cssnano](https://cssnano.co/) - Minifies CSS
- [postcss-easy-import](https://github.com/TrySound/postcss-easy-import) - Allows importing one stylesheet into another

## Limitations

### Dynamically generated class strings will be purged

Purgecss takes a very straightforward approach to removing unused CSS. It simply searches an entire file for a string that matches a regular expression. As a result, class strings that are dynamically created in a template using string concatenation will be considered unused and removed from your stylesheet. Tailwind CSS addresses this problem in more detail in [their documentation](https://tailwindcss.com/docs/controlling-file-size#writing-purgeable-html).
3 changes: 1 addition & 2 deletions examples/with-typescript/pages/api/users/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sampleUserData } from '../../../utils/sample-data'

export default (req: NextApiRequest, res: NextApiResponse) => {
try {
const { id } = req.query;
const { id } = req.query
const selected = sampleUserData.find(data => data.id === Number(id))

if (!selected) {
Expand All @@ -15,4 +15,3 @@ export default (req: NextApiRequest, res: NextApiResponse) => {
res.status(404).json({ statusCode: 404, message: err.message })
}
}

8 changes: 6 additions & 2 deletions examples/with-typescript/pages/users/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class InitialPropsDetail extends React.Component<Props> {
static getInitialProps = async ({ query }: NextPageContext) => {
try {
const { id } = query
const item = await sampleFetchWrapper(`http://localhost:3000/api/users/${Array.isArray(id) ? id[0] : id}`)
const item = await sampleFetchWrapper(
`http://localhost:3000/api/users/${Array.isArray(id) ? id[0] : id}`
)
return { item }
} catch (err) {
return { errors: err.message }
Expand All @@ -37,7 +39,9 @@ class InitialPropsDetail extends React.Component<Props> {

return (
<Layout
title={`${item ? item.name : 'User Detail'} | Next.js + TypeScript Example`}
title={`${
item ? item.name : 'User Detail'
} | Next.js + TypeScript Example`}
>
{item && <ListDetail item={item} />}
</Layout>
Expand Down
2 changes: 1 addition & 1 deletion examples/with-zeit-fetch/fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"browser": "./browser.js",
"main": "./server.js"
}
}
9 changes: 2 additions & 7 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"command": {
"version": {
"exact": true
},
"publish": {
"npmClient": "npm",
"allowBranch": [
"master",
"canary"
],
"allowBranch": ["master", "canary"],
"registry": "https://registry.npmjs.org/"
}
},
Expand Down
23 changes: 23 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const escape = require('shell-quote').quote

module.exports = {
'**/*.{js,jsx}': filenames => {
const escapedFileNames = filenames
.map(filename => `"${escape([filename])}"`)
.join(' ')
return [
`prettier --write ${escapedFileNames}`,
`standard --fix ${escapedFileNames}`,
`git add ${escapedFileNames}`
]
},
'**/*.{json,ts,tsx,md,mdx,css,html,yml,yaml,scss,sass}': filenames => {
const escapedFileNames = filenames
.map(filename => `"${escape([filename])}"`)
.join(' ')
return [
`prettier --write ${escapedFileNames}`,
`git add ${escapedFileNames}`
]
}
}
22 changes: 2 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@
"next": "./packages/next/dist/bin/next"
},
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
"prettier --write",
"standard --fix",
"git add"
],
"*.tsx": [
"prettier --write",
"git add"
],
"*.ts": [
"prettier --write",
"git add"
],
"*.md": [
"prettier --write",
"git add"
]
},
"standard": {
"parser": "babel-eslint",
"ignore": [
Expand Down Expand Up @@ -97,7 +78,7 @@
"jest-cli": "24.8.0",
"jest-junit": "6.4.0",
"lerna": "3.14.1",
"lint-staged": "8.1.7",
"lint-staged": "9.4.2",
"mkdirp": "0.5.1",
"moment": "^2.24.0",
"node-fetch": "2.6.0",
Expand All @@ -111,6 +92,7 @@
"release": "6.0.1",
"request-promise-core": "1.1.2",
"rimraf": "2.6.3",
"shell-quote": "1.7.2",
"standard": "12.0.1",
"taskr": "1.1.0",
"tree-kill": "1.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ export default async function getBaseWebpackConfig(
// are relative to requests we've already resolved here.
// Absolute requires (require('/foo')) are extremely uncommon, but
// also have no need for customization as they're already resolved.
const start = request.charAt(0);
const start = request.charAt(0)
if (start === '.' || start === '/') {
return callback();
return callback()
}

// Resolve the import with the webpack provided context, this
Expand Down
5 changes: 1 addition & 4 deletions test/integration/prerender/pages/blog/[post]/[comment].js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import Link from 'next/link'

// eslint-disable-next-line camelcase
export async function unstable_getStaticParams () {
return [
'/blog/post-1/comment-1',
{ post: 'post-2', comment: 'comment-2' }
]
return ['/blog/post-1/comment-1', { post: 'post-2', comment: 'comment-2' }]
}

// eslint-disable-next-line camelcase
Expand Down
6 changes: 1 addition & 5 deletions test/integration/prerender/pages/blog/[post]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import Link from 'next/link'

// eslint-disable-next-line camelcase
export async function unstable_getStaticParams () {
return [
'/blog/post-1',
{ post: 'post-2' },
'/blog/[post3]'
]
return ['/blog/post-1', { post: 'post-2' }, '/blog/[post3]']
}

// eslint-disable-next-line camelcase
Expand Down
Loading

0 comments on commit 6b54e9e

Please sign in to comment.