Skip to content

Commit

Permalink
feat(prettier): Introduce prettier and update all files
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg committed Nov 22, 2020
1 parent fc57953 commit c9b8984
Show file tree
Hide file tree
Showing 47 changed files with 371 additions and 402 deletions.
16 changes: 8 additions & 8 deletions .eslintrc.js
Expand Up @@ -3,10 +3,7 @@
const path = require('path');

module.exports = {
extends: [
'@scottnonnenberg/thehelp',
'@scottnonnenberg/thehelp/react',
],
extends: ['@scottnonnenberg/thehelp', '@scottnonnenberg/thehelp/react'],

parser: 'babel-eslint',

Expand All @@ -16,7 +13,7 @@ module.exports = {
paths: [__dirname, path.resolve(__dirname, 'test/setup/fakes')],
},
},
'react': {
react: {
version: '15.1.0',
},
},
Expand All @@ -28,8 +25,11 @@ module.exports = {

'security/detect-object-injection': 'off', // as a client-only app, no concerns here

'thehelp/absolute-or-current-dir': ['error', {
exceptions: [/setupModulePath$/],
}],
'thehelp/absolute-or-current-dir': [
'error',
{
exceptions: [/setupModulePath$/],
},
],
},
};
9 changes: 9 additions & 0 deletions .prettierignore
@@ -0,0 +1,9 @@
css/solarized-light.less
css/typography-compat.less

pages/posts/*

# Generated
CHANGELOG.md
.cache
public
6 changes: 6 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,6 @@
module.exports = {
arrowParens: 'avoid',
printWidth: 90,
singleQuote: true,
trailingComma: 'es5',
};
29 changes: 0 additions & 29 deletions gatsby-browser.js

This file was deleted.

3 changes: 2 additions & 1 deletion gatsby-config.js
Expand Up @@ -20,7 +20,8 @@ module.exports = {
url: 'https://scottnonnenberg.com',
image: 'https://static.sinap.ps/img/profile/me_2012_square_300px_full.png',
icon: 'https://static.sinap.ps/img/profile/me_2012_square_300px.jpg',
blurb: "Hi, I'm Scott. I've written both server and client code in many languages for many employers and clients. I've also got a bit of an unusual perspective, since I've spent time in roles outside the pure 'software developer.'",
blurb:
"Hi, I'm Scott. I've written both server and client code in many languages for many employers and clients. I've also got a bit of an unusual perspective, since I've spent time in roles outside the pure 'software developer.'",
},
},
plugins: [
Expand Down
18 changes: 4 additions & 14 deletions gatsby-node.js
@@ -1,14 +1,7 @@
/* eslint-disable import/no-commonjs, thehelp/no-mutation */

const path = require('path');
const {
filter,
flatten,
get,
includes,
sortBy,
uniq,
} = require('lodash');
const { filter, flatten, get, includes, sortBy, uniq } = require('lodash');

exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
Expand All @@ -18,9 +11,7 @@ exports.createPages = async ({ graphql, actions }) => {
const result = await graphql(
`
{
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: ASC }
) {
allMarkdownRemark(sort: { fields: [frontmatter___date], order: ASC }) {
edges {
node {
html
Expand Down Expand Up @@ -66,9 +57,8 @@ exports.createPages = async ({ graphql, actions }) => {
const tags = sortBy(uniq(flatten(posts.map(post => post.frontmatter.tags))));

tags.forEach(tag => {
const postsWithTag = filter(
posts,
post => includes(get(post, 'frontmatter.tags'), tag)
const postsWithTag = filter(posts, post =>
includes(get(post, 'frontmatter.tags'), tag)
);

createPage({
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
"prerelease": "npm run build-production",
"check-types": "tsc --noEmit",
"lint": "eslint .",
"format": "prettier --write \"*.{css,js,json,md,scss,ts,tsx}\" \"./**/*.{css,js,json,md,scss,ts,tsx}\"",
"develop": "gatsby develop",
"build": "gatsby build",
"build-production": "scripts/build.sh",
Expand Down Expand Up @@ -74,6 +75,7 @@
"markdown-it": "10.0.0",
"mocha": "7.1.2",
"npm-run-all": "4.1.5",
"prettier": "2.0.5",
"rimraf": "3.0.2",
"sinon": "9.0.2",
"standard-version": "7.1.0",
Expand Down
4 changes: 1 addition & 3 deletions scripts/.eslintrc.js
@@ -1,7 +1,5 @@
module.exports = {
extends: [
'@scottnonnenberg/thehelp/scripts',
],
extends: ['@scottnonnenberg/thehelp/scripts'],

rules: {
'consistent-return': 'off',
Expand Down
35 changes: 16 additions & 19 deletions scripts/check_deep_links.ts
Expand Up @@ -11,14 +11,16 @@ import superagent from 'superagent';
// @ts-ignore
import { SiteChecker } from 'broken-link-checker';


const MAX_PARALLEL = 5;
const DOMAIN = 'http://localhost:8000';
const links = Object.create(null);
const cache = Object.create(null);


function verifyHash({ pathname, hash, contents }: {
function verifyHash({
pathname,
hash,
contents,
}: {
pathname: string;
hash: string;
contents: string;
Expand All @@ -40,24 +42,22 @@ function verifyHash({ pathname, hash, contents }: {

type LinkType = {
pathname: string;
hash: string
hash: string;
};

function checkLink({ pathname, hash }: LinkType, cb: Function) {
if (cache[pathname]) {
return cb(null, verifyHash({ pathname, hash, contents: cache[pathname] }));
}

return superagent
.get(DOMAIN + pathname)
.end((err, res) => {
if (notate(cb, err, { pathname })) {
return;
}
return superagent.get(DOMAIN + pathname).end((err, res) => {
if (notate(cb, err, { pathname })) {
return;
}

cache[pathname] = res.text; // eslint-disable-line
return cb(null, verifyHash({ pathname, hash, contents: res.text }));
});
cache[pathname] = res.text; // eslint-disable-line
return cb(null, verifyHash({ pathname, hash, contents: res.text }));
});
}

function checkLinks() {
Expand All @@ -80,22 +80,20 @@ function checkLinks() {

console.log('\nAll Done!');
});
}
catch (err) {
} catch (err) {
console.log(notate.prettyPrint(err));
}
}


const options = {
excludeExternalLinks: true,
};

type SiteCheckerResultType = {
url: {
resolved: string;
}
}
};
};

const handlers = {
link: (result: SiteCheckerResultType) => {
Expand All @@ -107,4 +105,3 @@ const handlers = {
const checker = new SiteChecker(options, handlers);

checker.enqueue(DOMAIN);

5 changes: 1 addition & 4 deletions scripts/clean_post.ts
Expand Up @@ -9,7 +9,6 @@ import * as globalConfig from 'gatsby-config';

const config = globalConfig.siteMetadata;


const limit = parseInt(process.argv[2], 10) || 1;
const posts = loadPosts({
limit,
Expand All @@ -21,9 +20,7 @@ function removeSmartQuotes(value?: string) {
return value;
}

return value
.replace(/[’‘]/g, '\'')
.replace(/[“”]/g, '"');
return value.replace(/[’‘]/g, "'").replace(/[“”]/g, '"');
}

function removeDupeLinks(contents?: string) {
Expand Down
40 changes: 21 additions & 19 deletions scripts/generate_json.ts
Expand Up @@ -22,25 +22,27 @@ const config = globalConfig.siteMetadata;

const posts = loadPosts();

const json = compact(map(posts, post => {
if (!post.frontmatter) {
console.error('Malformed post', post);
throw new Error('Post was missing frontmatter!');
}

const preFoldContent = fixLocalLinks(getPreFoldContent(post.html), config.domain);
const url = config.domain + post.frontmatter.path;
const readMore = ` <a href="${url}">Read more&nbsp;»</a>`;
const withCallToAction = appendToLastTextBlock(preFoldContent, readMore);

return {
title: post.frontmatter.title,
date: post.frontmatter.date,
preview: withCallToAction,
url,
tags: post.frontmatter.tags,
};
}));
const json = compact(
map(posts, post => {
if (!post.frontmatter) {
console.error('Malformed post', post);
throw new Error('Post was missing frontmatter!');
}

const preFoldContent = fixLocalLinks(getPreFoldContent(post.html), config.domain);
const url = config.domain + post.frontmatter.path;
const readMore = ` <a href="${url}">Read more&nbsp;»</a>`;
const withCallToAction = appendToLastTextBlock(preFoldContent, readMore);

return {
title: post.frontmatter.title,
date: post.frontmatter.date,
preview: withCallToAction,
url,
tags: post.frontmatter.tags,
};
})
);

fs.writeFileSync(allPath, JSON.stringify(json, null, ' '));
fs.writeFileSync(recentPath, JSON.stringify(json.slice(0, RECENT_LIMIT), null, ' '));
7 changes: 4 additions & 3 deletions scripts/make_post.ts
Expand Up @@ -6,7 +6,6 @@ import _string from 'underscore.string';

import moment from 'moment';


function fixForYaml(title: string): string {
if (title.indexOf(':') !== -1) {
return `"${title.split('"').join('\\"')}"`;
Expand All @@ -32,7 +31,9 @@ const newContents = template
.replace('PATH', postPath);

const filePathDate = moment(now).format('YYYY-MM-DD');
const newFilePath =
path.join(__dirname, `../pages/posts/${filePathDate}-${titleSlug}.md`);
const newFilePath = path.join(
__dirname,
`../pages/posts/${filePathDate}-${titleSlug}.md`
);

fs.writeFileSync(newFilePath, newContents);
15 changes: 8 additions & 7 deletions scripts/util/loadPosts.ts
Expand Up @@ -17,12 +17,14 @@ const fileFilter = /.md$/;
type PostFrontMatterResultType = {
attributes: PostAttributesType;
body: string;
}

export default function loadPosts(options: {
limit?: number;
markdown?: boolean;
} = {}): Array<PostType> {
};

export default function loadPosts(
options: {
limit?: number;
markdown?: boolean;
} = {}
): Array<PostType> {
const limit = options.limit || Infinity;
const markdown = typeof options.markdown === 'undefined' ? true : options.markdown;

Expand Down Expand Up @@ -51,4 +53,3 @@ export default function loadPosts(options: {
})
.value();
}

3 changes: 1 addition & 2 deletions scripts/util/writeIfDifferent.ts
Expand Up @@ -6,8 +6,7 @@ export default function writeIfDifferent(path: string, contents: string) {
if (currentContents === contents) {
return;
}
}
catch (err) {
} catch (err) {
// file doesn't exist; need to write it
}

Expand Down

0 comments on commit c9b8984

Please sign in to comment.