feat: use eslint with prettier to format code

This commit is contained in:
Valeriy
2019-02-19 01:59:12 +03:00
committed by mrugesh mohapatra
parent be36915605
commit fc8c71ad16
70 changed files with 254 additions and 236 deletions

View File

@ -25,7 +25,7 @@ export default function addReturnToUrl() {
req.method !== 'GET' || req.method !== 'GET' ||
pathsOfNoReturnRegex.test(path) || pathsOfNoReturnRegex.test(path) ||
!whiteListRegex.test(path) || !whiteListRegex.test(path) ||
(/hot/i).test(req.path) /hot/i.test(req.path)
) { ) {
return next(); return next();
} }

View File

@ -8,7 +8,7 @@ export default function() {
}); });
return function csrf(req, res, next) { return function csrf(req, res, next) {
const path = req.path.split('/')[1]; const path = req.path.split('/')[1];
if ((/(^api$|^unauthenticated$|^internal$|^p$)/).test(path)) { if (/(^api$|^unauthenticated$|^internal$|^p$)/.test(path)) {
return next(); return next();
} }
return protection(req, res, next); return protection(req, res, next);

View File

@ -49,7 +49,9 @@ export function _cachedMap({ Block, Challenge }) {
}); });
const blockMap = Observable.combineLatest( const blockMap = Observable.combineLatest(
blocks.map(blocks => blocks.map(blocks =>
blocks.map(block => block.toJSON()).reduce((hash, block) => { blocks
.map(block => block.toJSON())
.reduce((hash, block) => {
hash[block.dashedName] = block; hash[block.dashedName] = block;
return hash; return hash;
}, {}) }, {})

View File

@ -35,14 +35,14 @@ export const wrapPageElement = ({ element, props }) => {
</DefaultLayout> </DefaultLayout>
); );
} }
if ((/^\/guide(\/.*)*/).test(pathname)) { if (/^\/guide(\/.*)*/.test(pathname)) {
return ( return (
<DefaultLayout> <DefaultLayout>
<GuideLayout>{element}</GuideLayout> <GuideLayout>{element}</GuideLayout>
</DefaultLayout> </DefaultLayout>
); );
} }
if ((/^\/learn(\/.*)*/).test(pathname)) { if (/^\/learn(\/.*)*/.test(pathname)) {
return <DefaultLayout showFooter={false}>{element}</DefaultLayout>; return <DefaultLayout showFooter={false}>{element}</DefaultLayout>;
} }
return <DefaultLayout>{element}</DefaultLayout>; return <DefaultLayout>{element}</DefaultLayout>;

View File

@ -148,8 +148,8 @@ exports.onCreateWebpackConfig = ({ stage, rules, plugins, actions }) => {
/* eslint-disable max-len */ /* eslint-disable max-len */
exclude: modulePath => { exclude: modulePath => {
return ( return (
(/node_modules/).test(modulePath) && /node_modules/.test(modulePath) &&
!(/(ansi-styles|chalk|strict-uri-encode|react-freecodecamp-search)/).test( !/(ansi-styles|chalk|strict-uri-encode|react-freecodecamp-search)/.test(
modulePath modulePath
) )
); );

View File

@ -35,14 +35,14 @@ export const wrapPageElement = ({ element, props }) => {
</DefaultLayout> </DefaultLayout>
); );
} }
if ((/^\/guide(\/.*)*/).test(pathname)) { if (/^\/guide(\/.*)*/.test(pathname)) {
return ( return (
<DefaultLayout> <DefaultLayout>
<GuideLayout>{element}</GuideLayout> <GuideLayout>{element}</GuideLayout>
</DefaultLayout> </DefaultLayout>
); );
} }
if ((/^\/learn(\/.*)*/).test(pathname)) { if (/^\/learn(\/.*)*/.test(pathname)) {
return <DefaultLayout showFooter={false}>{element}</DefaultLayout>; return <DefaultLayout showFooter={false}>{element}</DefaultLayout>;
} }
return <DefaultLayout>{element}</DefaultLayout>; return <DefaultLayout>{element}</DefaultLayout>;

View File

@ -31,10 +31,8 @@ exports.sourceNodes = function sourceChallengesSourceNodes(
persistent: true persistent: true
}); });
watcher.on('ready', sourceAndCreateNodes).on( watcher.on('ready', sourceAndCreateNodes).on('change', filePath =>
'change', /\.md$/.test(filePath)
filePath =>
(/\.md$/).test(filePath)
? onSourceChange(filePath) ? onSourceChange(filePath)
.then(challenge => { .then(challenge => {
reporter.info( reporter.info(

View File

@ -20,10 +20,7 @@ function markdownToHTML(node) {
} }
module.exports = function forumEmojiPlugin({ markdownAST }) { module.exports = function forumEmojiPlugin({ markdownAST }) {
visit( visit(markdownAST, 'image', imageNode =>
markdownAST,
'image',
imageNode =>
emojiRE.test(imageNode.title) ? markdownToHTML(imageNode) : imageNode emojiRE.test(imageNode.title) ? markdownToHTML(imageNode) : imageNode
); );
}; };

View File

@ -20,9 +20,12 @@ import DonateText from './DonateText';
import '../Donation.css'; import '../Donation.css';
const mapStateToProps = createSelector(isDonationModalOpenSelector, show => ({ const mapStateToProps = createSelector(
isDonationModalOpenSelector,
show => ({
show show
})); })
);
const mapDispatchToProps = dispatch => const mapDispatchToProps = dispatch =>
bindActionCreators( bindActionCreators(

View File

@ -19,7 +19,7 @@ const ColHeader = ({ children, ...other }) => (
ColHeader.propTypes = propTypes; ColHeader.propTypes = propTypes;
const Link = ({ children, to, external, ...other }) => { const Link = ({ children, to, external, ...other }) => {
if (!external && (/^\/(?!\/)/).test(to)) { if (!external && /^\/(?!\/)/.test(to)) {
return ( return (
<GatsbyLink to={to} {...other}> <GatsbyLink to={to} {...other}>
{children} {children}

View File

@ -12,9 +12,12 @@ import { gtagReportConversion } from '../../../analytics/gtag';
import './login.css'; import './login.css';
const mapStateToProps = createSelector(isSignedInSelector, isSignedIn => ({ const mapStateToProps = createSelector(
isSignedInSelector,
isSignedIn => ({
isSignedIn isSignedIn
})); })
);
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
navigate: location => dispatch(hardGoTo(location)) navigate: location => dispatch(hardGoTo(location))
}); });

View File

@ -6,9 +6,12 @@ import { createSelector } from 'reselect';
import { userSelector } from '../../../redux'; import { userSelector } from '../../../redux';
const mapStateToProps = createSelector(userSelector, ({ picture }) => ({ const mapStateToProps = createSelector(
userSelector,
({ picture }) => ({
picture picture
})); })
);
function SignedIn({ picture }) { function SignedIn({ picture }) {
return ( return (

View File

@ -14,9 +14,10 @@ import { ChallengeNode } from '../../../redux/propTypes';
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {
const expandedSelector = makeExpandedSuperBlockSelector(ownProps.superBlock); const expandedSelector = makeExpandedSuperBlockSelector(ownProps.superBlock);
return createSelector(expandedSelector, isExpanded => ({ isExpanded }))( return createSelector(
state expandedSelector,
); isExpanded => ({ isExpanded })
)(state);
}; };
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {

View File

@ -65,7 +65,7 @@ export function getValidationState(field) {
return null; return null;
} }
if ((/https?:\/\/glitch\.com\/edit\/#!\/.*/g).test(field.value)) { if (/https?:\/\/glitch\.com\/edit\/#!\/.*/g.test(field.value)) {
return 'glitch-warning'; return 'glitch-warning';
} }

View File

@ -177,7 +177,7 @@ class PortfolioSettings extends Component {
if (isImage && !maybeUrl) { if (isImage && !maybeUrl) {
return { state: null, message: '' }; return { state: null, message: '' };
} }
if (isImage && !(/\.(png|jpg|jpeg|gif)$/).test(maybeUrl)) { if (isImage && !/\.(png|jpg|jpeg|gif)$/.test(maybeUrl)) {
return { return {
state: 'error', state: 'error',
message: 'URL must link directly to an image file' message: 'URL must link directly to an image file'

View File

@ -14,10 +14,13 @@ import Spacer from '../helpers/Spacer';
import ToggleSetting from './ToggleSetting'; import ToggleSetting from './ToggleSetting';
import SectionHeader from './SectionHeader'; import SectionHeader from './SectionHeader';
const mapStateToProps = createSelector(userSelector, user => ({ const mapStateToProps = createSelector(
userSelector,
user => ({
...user.profileUI, ...user.profileUI,
user user
})); })
);
const mapDispatchToProps = dispatch => const mapDispatchToProps = dispatch =>
bindActionCreators({ submitProfileUI }, dispatch); bindActionCreators({ submitProfileUI }, dispatch);
@ -130,7 +133,7 @@ class PrivacySettings extends Component {
toggleFlag={this.toggleFlag('showLocation')} toggleFlag={this.toggleFlag('showLocation')}
/> />
<ToggleSetting <ToggleSetting
action='My &quot;about me&quot;' action='My "about me"'
flag={!showAbout} flag={!showAbout}
flagName='showAbout' flagName='showAbout'
offLabel='Public' offLabel='Public'

View File

@ -91,9 +91,8 @@ class UsernameSettings extends Component {
characterValidation: { valid } characterValidation: { valid }
} = this.state; } = this.state;
return this.setState( return this.setState({ submitClicked: true }, () =>
{ submitClicked: true }, valid ? submitNewUsername(formValue) : null
() => (valid ? submitNewUsername(formValue) : null)
); );
} }

View File

@ -10,7 +10,7 @@ const propTypes = {
}; };
function emptyInstruction(instructions) { function emptyInstruction(instructions) {
return (/^<section\s+id\s*=\s*("|')instructions\1\s*>\s*<\/section>$/).test( return /^<section\s+id\s*=\s*("|')instructions\1\s*>\s*<\/section>$/.test(
instructions instructions
); );
} }

View File

@ -16,9 +16,12 @@ const propTypes = {
reset: PropTypes.func.isRequired reset: PropTypes.func.isRequired
}; };
const mapStateToProps = createSelector(isResetModalOpenSelector, isOpen => ({ const mapStateToProps = createSelector(
isResetModalOpenSelector,
isOpen => ({
isOpen isOpen
})); })
);
const mapDispatchToProps = dispatch => const mapDispatchToProps = dispatch =>
bindActionCreators( bindActionCreators(

View File

@ -13,9 +13,12 @@ import { initConsole, challengeTestsSelector } from '../redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import './side-panel.css'; import './side-panel.css';
const mapStateToProps = createSelector(challengeTestsSelector, tests => ({ const mapStateToProps = createSelector(
challengeTestsSelector,
tests => ({
tests tests
})); })
);
const mapDispatchToProps = dispatch => const mapDispatchToProps = dispatch =>
bindActionCreators( bindActionCreators(

View File

@ -59,4 +59,3 @@ export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(ToolPanel); )(ToolPanel);

View File

@ -105,7 +105,9 @@ function loadCodeEpic(action$, state$) {
const codeFound = getCode(id); const codeFound = getCode(id);
if (codeFound && isFilesAllPoly(codeFound)) { if (codeFound && isFilesAllPoly(codeFound)) {
finalFiles = { finalFiles = {
...fileKeys.map(key => files[key]).reduce( ...fileKeys
.map(key => files[key])
.reduce(
(files, file) => ({ (files, file) => ({
...files, ...files,
[file.key]: { [file.key]: {

View File

@ -23,7 +23,9 @@ const propTypes = {
}; };
function renderMenuItems({ edges = [] }) { function renderMenuItems({ edges = [] }) {
return edges.map(({ node }) => node).map(({ title, fields: { slug } }) => ( return edges
.map(({ node }) => node)
.map(({ title, fields: { slug } }) => (
<Link key={'intro-' + slug} to={slug}> <Link key={'intro-' + slug} to={slug}>
<ListGroupItem>{title}</ListGroupItem> <ListGroupItem>{title}</ListGroupItem>
</Link> </Link>

View File

@ -45,7 +45,7 @@ function textToData(sectionIds) {
const lines = child.value.split('\n'); const lines = child.value.split('\n');
if (lines.filter(Boolean).length > 0) { if (lines.filter(Boolean).length > 0) {
lines.forEach((line, index) => { lines.forEach((line, index) => {
if ((/^\s*$/).test(line)) { if (/^\s*$/.test(line)) {
currentParagraph = null; currentParagraph = null;
} else { } else {
if (!currentParagraph || index > 0) { if (!currentParagraph || index > 0) {

View File

@ -70,7 +70,7 @@ const challengeFrontmatterValidator = file => frontmatter => {
function isChallengeParseable(file) { function isChallengeParseable(file) {
const { stat, fullPath } = file; const { stat, fullPath } = file;
if (!stat.isFile() || (/_meta/).test(fullPath)) { if (!stat.isFile() || /_meta/.test(fullPath)) {
return Promise.resolve(true); return Promise.resolve(true);
} }
return parseMarkdown(fullPath); return parseMarkdown(fullPath);