Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up ESLint usage #836

Merged
merged 6 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
static/**/*.js
build
node_modules
105 changes: 79 additions & 26 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,82 @@ const WARNING = 1;
const ERROR = 2;

module.exports = {
extends: [
'fbjs', // eslint-config-fbjs
'prettier' // eslint-config-prettier
],
overrides: [
{
files: ['lib/**/*.js'],
rules: {
// allow console
'no-console': OFF,
// require radix argument in parseInt
'radix': ERROR,
// disallow unused vars
'no-unused-vars': ERROR,
// almost certainly a bug
'no-duplicate-case': ERROR,
}
},
{
files: ['examples/**/*.js'],
rules: {
'no-unused-vars': OFF
}
}
]
};
env: {
browser: true,
commonjs: true,
jest: true,
node: true,
},
parser: 'babel-eslint',
extends: ['airbnb', 'prettier'],
rules: {
// allow console
'no-console': OFF,
// require radix argument in parseInt
radix: ERROR,
// Existing ESLint errors sorted by frequency, silencing first.
'react/button-has-type': OFF, // 1
null: OFF, // 1
'react/no-unused-state': OFF, // 1
'vars-on-top': OFF, // 1
'react/forbid-prop-types': OFF, // 1
'react/require-default-props': OFF, // 1
'lines-between-class-members': OFF, // 1
strict: OFF, // 1
'no-restricted-syntax': OFF, // 1
'no-path-concat': OFF, // 2
'one-var': OFF, // 2
'no-unused-expressions': OFF, // 2
'react/jsx-boolean-value': OFF, // 2
'jsx-a11y/html-has-lang': OFF, // 2
'no-var': OFF, // 2
'no-useless-return': OFF, // 2
'jsx-a11y/anchor-has-content': OFF, // 2
'react/jsx-no-comment-textnodes': OFF, // 3
'no-continue': OFF, // 3
'jsx-a11y/alt-text': OFF, // 3
'react/jsx-tag-spacing': OFF, // 3
'no-lonely-if': OFF, // 3
'react/sort-comp': OFF, // 4
'no-cond-assign': OFF, // 4
'no-use-before-define': OFF, // 4
'no-empty': OFF, // 4
'no-shadow': OFF, // 4
'class-methods-use-this': OFF, // 5
eqeqeq: OFF, // 5
'react/no-multi-comp': OFF, // 5
'react/no-array-index-key': OFF, // 6
'no-underscore-dangle': OFF, // 6
'array-callback-return': OFF, // 6
'import/no-extraneous-dependencies': OFF, // 7
'no-else-return': OFF, // 9
'jsx-a11y/anchor-is-valid': OFF, // 9
'import/order': OFF, // 10
'arrow-body-style': OFF, // 10
camelcase: OFF, // 10
'react/jsx-curly-brace-presence': OFF, // 11
'react/no-unescaped-entities': OFF, // 12
'no-param-reassign': OFF, // 12
'no-unused-vars': OFF, // 13
'spaced-comment': OFF, // 14
'import/no-unresolved': OFF, // 15
'react/no-danger': OFF, // 16
'object-shorthand': OFF, // 16
'dot-notation': OFF, // 19
'react/prefer-stateless-function': OFF, // 22
'no-plusplus': OFF, // 23
'prefer-arrow-callback': OFF, // 30
'react/jsx-filename-extension': OFF, // 31
'import/newline-after-import': OFF, // 31
'react/jsx-closing-bracket-location': OFF, // 36
'func-names': OFF, // 37
'import/no-dynamic-require': OFF, // 46
'prefer-destructuring': OFF, // 69
'prefer-const': OFF, // 71
'global-require': OFF, // 85
'react/jsx-one-expression-per-line': OFF, // 129
'react/prop-types': OFF, // 197
'prefer-template': OFF, // 292
'react/destructuring-assignment': OFF, // 342
},
};
1 change: 0 additions & 1 deletion examples/basics/core/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Footer extends React.Component {
}

render() {
const currentYear = new Date().getFullYear();
return (
<footer className="nav-footer" id="footer">
<section className="sitemap">
Expand Down
2 changes: 0 additions & 2 deletions examples/translations/pages/en/help-with-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const GridBlock = CompLibrary.GridBlock;

const translate = require('../../server/translate.js').translate;

const siteConfig = require(process.cwd() + '/siteConfig.js');

class Help extends React.Component {
render() {
const supportLinks = [
Expand Down
146 changes: 73 additions & 73 deletions examples/versions/pages/en/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,85 +9,85 @@ const React = require('react');

const CompLibrary = require('../../core/CompLibrary');
const Container = CompLibrary.Container;
const GridBlock = CompLibrary.GridBlock;

const CWD = process.cwd();

const siteConfig = require(CWD + '/siteConfig.js');
const versions = require(CWD + '/versions.json');

class Versions extends React.Component {
render() {
const latestVersion = versions[0];
return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer versionsContainer">
<div className="post">
<header className="postHeader">
<h2>{siteConfig.title + ' Versions'}</h2>
</header>
<p>New versions of this project are released every so often.</p>
<h3 id="latest">Current version (Stable)</h3>
<table className="versions">
<tbody>
<tr>
<th>{latestVersion}</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
</tbody>
</table>
<p>
This is the version that is configured automatically when you
first install this project.
</p>
<h3 id="rc">Pre-release versions</h3>
<table className="versions">
<tbody>
<tr>
<th>master</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
</tbody>
</table>
<p>Other text describing this section.</p>
<h3 id="archive">Past Versions</h3>
<table className="versions">
<tbody>
{versions.map(
version =>
version !== latestVersion && (
<tr>
<th>{version}</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
)
)}
</tbody>
</table>
<p>
You can find past versions of this project{' '}
<a href="https://github.com/"> on GitHub </a>.
</p>
</div>
</Container>
</div>
);
}
function Versions() {
const latestVersion = versions[0];
const repoUrl = `https://github.com/${siteConfig.organizationName}/${
siteConfig.projectName
}`;
return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer versionsContainer">
<div className="post">
<header className="postHeader">
<h1>{siteConfig.title} Versions</h1>
</header>
<p>New versions of this project are released every so often.</p>
<h3 id="latest">Current version (Stable)</h3>
<table className="versions">
<tbody>
<tr>
<th>{latestVersion}</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
</tbody>
</table>
<p>
This is the version that is configured automatically when you first
install this project.
</p>
<h3 id="rc">Pre-release versions</h3>
<table className="versions">
<tbody>
<tr>
<th>master</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
</tbody>
</table>
<p>Other text describing this section.</p>
<h3 id="archive">Past Versions</h3>
<table className="versions">
<tbody>
{versions.map(
version =>
version !== latestVersion && (
<tr>
<th>{version}</th>
<td>
<a href={''}>Documentation</a>
</td>
<td>
<a href={''}>Release Notes</a>
</td>
</tr>
)
)}
</tbody>
</table>
<p>
You can find past versions of this project on{' '}
<a href={repoUrl}>GitHub</a>.
</p>
</div>
</Container>
</div>
);
}

module.exports = Versions;
20 changes: 9 additions & 11 deletions lib/core/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const escape = require('escape-string-regexp');

function blogRouting(baseUrl) {
return new RegExp(`^${escape(baseUrl)}blog\/.*html$`);
return new RegExp(`^${baseUrl}blog/.*html$`);
}

function docsRouting(baseUrl) {
return new RegExp(`^${escape(baseUrl)}docs\/.*html$`);
return new RegExp(`^${baseUrl}docs/.*html$`);
}

function dotRouting() {
return /(?!.*html$)^\/.*\.[^\n\/]+$/;
return /(?!.*html$)^\/.*\.[^\n/]+$/;
}

function feedRouting(baseUrl) {
return new RegExp(`^${escape(baseUrl)}blog\/(feed\.xml|atom\.xml)$`);
return new RegExp(`^${baseUrl}blog/(feed.xml|atom.xml)$`);
}

function noExtRouting() {
return /\/[^\.]*\/?$/;
return /\/[^.]*\/?$/;
}

function pageRouting(baseUrl) {
const gr = regex => regex.toString().replace(/(^\/|\/$)/gm, '');
return new RegExp(
`(?!${gr(docsRouting(baseUrl))}|${gr(blogRouting(baseUrl))})^${escape(
baseUrl
)}.*\.html$`
`(?!${gr(docsRouting(baseUrl))}|${gr(
blogRouting(baseUrl)
)})^${baseUrl}.*.html$`
);
}

function sitemapRouting(baseUrl) {
return new RegExp(`^${escape(baseUrl)}sitemap.xml$`);
return new RegExp(`^${baseUrl}sitemap.xml$`);
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rename-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CWD = process.cwd();

// escape appropriate characters in a string to be used in a regex
RegExp.escape = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
};

// generate a doc header from metadata
Expand Down
Loading