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' ||
pathsOfNoReturnRegex.test(path) ||
!whiteListRegex.test(path) ||
(/hot/i).test(req.path)
/hot/i.test(req.path)
) {
return next();
}

View File

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

View File

@ -17,7 +17,7 @@ const getFirstChallenge = _.once(_getFirstChallenge);
* interface ChallengeMap {
* result: {
* superBlocks: [ ...superBlockDashedName: String ]
* },
* },
* entities: {
* superBlock: {
* [ ...superBlockDashedName ]: SuperBlock
@ -49,7 +49,9 @@ export function _cachedMap({ Block, Challenge }) {
});
const blockMap = Observable.combineLatest(
blocks.map(blocks =>
blocks.map(block => block.toJSON()).reduce((hash, block) => {
blocks
.map(block => block.toJSON())
.reduce((hash, block) => {
hash[block.dashedName] = block;
return hash;
}, {})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -177,7 +177,7 @@ class PortfolioSettings extends Component {
if (isImage && !maybeUrl) {
return { state: null, message: '' };
}
if (isImage && !(/\.(png|jpg|jpeg|gif)$/).test(maybeUrl)) {
if (isImage && !/\.(png|jpg|jpeg|gif)$/.test(maybeUrl)) {
return {
state: 'error',
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 SectionHeader from './SectionHeader';
const mapStateToProps = createSelector(userSelector, user => ({
const mapStateToProps = createSelector(
userSelector,
user => ({
...user.profileUI,
user
}));
})
);
const mapDispatchToProps = dispatch =>
bindActionCreators({ submitProfileUI }, dispatch);
@ -130,7 +133,7 @@ class PrivacySettings extends Component {
toggleFlag={this.toggleFlag('showLocation')}
/>
<ToggleSetting
action='My &quot;about me&quot;'
action='My "about me"'
flag={!showAbout}
flagName='showAbout'
offLabel='Public'

View File

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

View File

@ -10,7 +10,7 @@ const propTypes = {
};
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
);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -92,7 +92,7 @@ function getJSTestRunner({ build, sources }, proxyLogger) {
const testWorker = createWorker('test-evaluator');
return async(testString, testTimeout) => {
return async (testString, testTimeout) => {
try {
testWorker.on('LOG', proxyLogger);
return await testWorker.execute(

View File

@ -98,7 +98,7 @@ const initTestFrame = frameReady => ctx => {
resolve();
}
});
contentLoaded.then(async() => {
contentLoaded.then(async () => {
const { sources, loadEnzyme } = ctx;
// default for classic challenges
// should not be used for modern

View File

@ -23,7 +23,9 @@ const propTypes = {
};
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}>
<ListGroupItem>{title}</ListGroupItem>
</Link>

View File

@ -43,7 +43,7 @@ async function translateChallenge(file) {
translateText(instructions),
...tests.map(
test =>
new Promise(async(resolve, reject) => {
new Promise(async (resolve, reject) => {
const { testString, text } = test;
const translatedText = await translateText(text).catch(reject);
return resolve({
@ -62,7 +62,7 @@ ${YAML.dump(
localeTitle: title ? title.join(' ').trim() : ''
}),
{ lineWidth: 10000 }
)}---
)}---
## Description
${description}
@ -101,7 +101,7 @@ ${solution}
`
)
.join('\n')
}
}
</section>
`;
@ -137,7 +137,7 @@ ${head}
</div>`
: ''
}
}
${
tail.length
? `
@ -150,7 +150,7 @@ console.info('after the test');
</div>`
: ''
}
}
`;
});
}

View File

@ -289,7 +289,7 @@ async function createTestRunnerForDOMChallenge(
await context.reload();
await context.setContent(build);
await context.evaluate(
async(sources, loadEnzyme) => {
async (sources, loadEnzyme) => {
const code = sources && 'index' in sources ? sources['index'] : '';
const getUserInput = fileName => sources[fileName];
await document.__initTestFrame({ code, getUserInput, loadEnzyme });
@ -298,7 +298,7 @@ async function createTestRunnerForDOMChallenge(
loadEnzyme
);
return async({ text, testString }) => {
return async ({ text, testString }) => {
try {
const { pass, err } = await Promise.race([
new Promise((_, reject) => setTimeout(() => reject('timeout'), 5000)),
@ -327,7 +327,7 @@ async function createTestRunnerForJSChallenge({ files }, solution) {
const code = sources && 'index' in sources ? sources['index'] : '';
const testWorker = createWorker('test-evaluator');
return async({ text, testString }) => {
return async ({ text, testString }) => {
try {
const { pass, err } = await testWorker.execute(
{ testString, build, code, sources },

View File

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

View File

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