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

Integrate eslint & precommit to codebase #815

Merged
merged 5 commits into from
Jul 1, 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- run: *yarn
- save-cache: *save-yarn-cache
- run:
name: Check Prettier
name: Check Prettier & ESLint
command: yarn ci-check
- run:
name: Run Test Suites
Expand Down
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const OFF = 0;
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
}
}
]
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

node_modules

.eslintcache
lib/core/metadata.js
lib/core/MetadataBlog.js
lib/pages/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Please make sure the following is done when submitting a pull request:
1. Fork [the repository](https://github.com/facebook/docusaurus) and create your branch from `master`.
1. Add the copyright notice to the top of any code new files you've added.
1. Describe your [**test plan**](#test-plan) in your pull request description. Make sure to [test your changes](https://github.com/facebook/Docusaurus/blob/master/admin/testing-changes-on-Docusaurus-itself.md)!
1. Make sure your code lints (`npm run prettier`).
1. Make sure your code lints (`npm run prettier && npm run lint`).
1. Make sure our Jest tests pass (`npm run test`).
1. If you haven't already, [sign the CLA](https://code.facebook.com/cla).

Expand Down
5 changes: 2 additions & 3 deletions lib/__tests__/build-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ beforeAll(() => {
});
});

function afterAll() {
afterAll(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the meaning - It was declaring a function before, now it's executing it. The after version looks more correct though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. it's actually caught by the linter. Otherwise the function is never used

clearBuildFolder();
}
});

test('Build folder exists', function() {
return fs.stat(buildDir).then(function(status) {
Expand All @@ -73,7 +73,6 @@ test('Generated HTML for each Markdown resource', function() {
metadata.push(path.basename());
});
inputMarkdownFiles.forEach(function(file) {
const path = filepath.create(file);
const data = fs.readFileSync(file, 'utf8');
const frontmatter = fm(data);
expect(metadata).toContain(frontmatter.attributes.id + '.html');
Expand Down
2 changes: 0 additions & 2 deletions lib/core/DocsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

const Metadata = require('./metadata.js');
const React = require('react');
const Container = require('./Container.js');
const SideNav = require('./nav/SideNav.js');
const siteConfig = require(process.cwd() + '/siteConfig.js');
const readCategories = require('../server/readCategories.js');

class DocsSidebar extends React.Component {
Expand Down
7 changes: 0 additions & 7 deletions lib/core/Redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
*/

const React = require('react');
const fs = require('fs');
const Head = require('./Head.js');
const translation = require('../server/translation.js');

const CWD = process.cwd();

// Component used to provide same head, header, footer, other scripts to all pages
class Redirect extends React.Component {
render() {
Expand All @@ -28,13 +25,9 @@ class Redirect extends React.Component {
this.props.config.url +
this.props.config.baseUrl +
(this.props.url || 'index.html');
let latestVersion;

const redirect = this.props.redirect || false;

if (fs.existsSync(CWD + '/versions.json')) {
latestVersion = require(CWD + '/versions.json')[0];
}
return (
<html>
<Head
Expand Down
2 changes: 0 additions & 2 deletions lib/core/Remarkable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
const React = require('react');
const renderMarkdown = require('./renderMarkdown.js');

const CWD = process.cwd();

class Remarkable extends React.Component {
content() {
if (this.props.source) {
Expand Down
1 change: 0 additions & 1 deletion lib/core/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const React = require('react');
const fs = require('fs');
const classNames = require('classnames');

const HeaderNav = require('./nav/HeaderNav.js');
const Head = require('./Head.js');
Expand Down
6 changes: 3 additions & 3 deletions lib/publish-gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ shell.exec('git rm -rf .');

shell.cd('../..');

fromPath = path.join('build', `${PROJECT_NAME}`);
toPath = path.join('build', `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
const fromPath = path.join('build', `${PROJECT_NAME}`);
const toPath = path.join('build', `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
// In github.io case, project is deployed to root. Need to not recursively
// copy the deployment-branch to be.
excludePath = `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`;
const excludePath = `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`;

// cannot use shell.cp because it doesn't support copying dotfiles and we
// need to copy directories like .circleci, for example
Expand Down
1 change: 0 additions & 1 deletion lib/rename-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const chalk = require('chalk');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const readMetadata = require('./server/readMetadata.js');
const metadataUtils = require('./server/metadataUtils.js');

const CWD = process.cwd();
Expand Down
20 changes: 1 addition & 19 deletions lib/server/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const Feed = require('feed');

const chalk = require('chalk');
const CWD = process.cwd();

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

const blogFolder = path.resolve('../blog/');
const readMetadata = require('./readMetadata.js');
const blogRootURL = siteConfig.url + siteConfig.baseUrl + 'blog';
const siteImageURL =
siteConfig.url + siteConfig.baseUrl + siteConfig.headerIcon;
const utils = require('../core/utils');

const renderMarkdown = require('../core/renderMarkdown.js');

/****************************************************************************/

let readMetadata;
let Metadata;

readMetadata = require('./readMetadata.js');
readMetadata.generateMetadataDocs();
Metadata = require('../core/metadata.js');

/****************************************************************************/

module.exports = function(type) {
console.log('feed.js triggered...');

Expand Down
12 changes: 6 additions & 6 deletions lib/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

async function execute() {
const extractTranslations = require('../write-translations.js');
require('../write-translations.js');

const metadataUtils = require('./metadataUtils');

Expand All @@ -15,7 +15,6 @@ async function execute() {
const fs = require('fs-extra');
const readMetadata = require('./readMetadata.js');
const path = require('path');
const color = require('color');
const getTOC = require('../core/getTOC.js');
const React = require('react');
const mkdirp = require('mkdirp');
Expand Down Expand Up @@ -321,9 +320,11 @@ async function execute() {

// create sitemap
if (MetadataBlog.length > 0 || Object.keys(Metadata).length > 0) {
let targetFile = join(buildDir, 'sitemap.xml');
sitemap(xml => {
writeFileAndCreateFolder(targetFile, xml);
sitemap((err, xml) => {
if (!err) {
const targetFile = join(buildDir, 'sitemap.xml');
writeFileAndCreateFolder(targetFile, xml);
}
});
}

Expand Down Expand Up @@ -454,7 +455,6 @@ async function execute() {
fs.writeFileSync(mainCss, css);

// compile/copy pages from user
let pagesArr = [];
files = glob.sync(join(CWD, 'pages', '**'));
files.forEach(file => {
// Why normalize? In case we are on Windows.
Expand Down
5 changes: 1 addition & 4 deletions lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const CWD = process.cwd();
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const chalk = require('chalk');

const metadataUtils = require('./metadataUtils');

Expand Down Expand Up @@ -180,8 +179,6 @@ function generateMetadataDocs() {
const docsDir = path.join(CWD, '../', getDocsPath());
let files = glob.sync(CWD + '/../' + getDocsPath() + '/**');
files.forEach(file => {
let language = 'en';

const extension = path.extname(file);

if (extension === '.md' || extension === '.markdown') {
Expand Down Expand Up @@ -359,7 +356,7 @@ function generateMetadataBlog() {
});

const sortedMetadatas = metadatas.sort(
(a, b) => parseInt(b.seconds) - parseInt(a.seconds)
(a, b) => parseInt(b.seconds, 10) - parseInt(a.seconds, 10)
);

fs.writeFileSync(
Expand Down
14 changes: 7 additions & 7 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ function execute(port, options) {
const metadataUtils = require('./metadataUtils');

const env = require('./env.js');
const translation = require('./translation');
const express = require('express');
const React = require('react');
const request = require('request');
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const color = require('color');
const getTOC = require('../core/getTOC');
const {
blogRouting,
Expand Down Expand Up @@ -284,10 +281,13 @@ function execute(port, options) {
});

app.get(sitemapRouting(siteConfig.baseUrl), (req, res) => {
res.set('Content-Type', 'application/xml');

sitemap(xml => {
res.send(xml);
sitemap((err, xml) => {
if (err) {
res.status(500).send('Sitemap error');
} else {
res.set('Content-Type', 'application/xml');
res.send(xml);
}
});
});

Expand Down
9 changes: 1 addition & 8 deletions lib/server/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
*/

const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const Feed = require('feed');

const chalk = require('chalk');
const glob = require('glob');
const CWD = process.cwd();

Expand Down Expand Up @@ -104,9 +100,6 @@ module.exports = function(callback) {
});

sm.toXML((err, xml) => {
if (err) {
return 'An error has occurred.';
}
callback(xml);
callback(err, xml);
});
};
1 change: 0 additions & 1 deletion lib/server/versionFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const CWD = process.cwd();
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const assert = require('assert');

const metadataUtils = require('./metadataUtils');

Expand Down
Loading