Skip to content

Commit 386d90d

Browse files
committed
chore: Update lint config and fix errors
1 parent 7e6bdac commit 386d90d

File tree

9 files changed

+312
-118
lines changed

9 files changed

+312
-118
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
2-
"extends": [ "fernandopasik", "fernandopasik/es6", "fernandopasik/react" ],
2+
"extends": [ "airbnb" ],
33
"env": {
44
"node": true
55
},
66
"parserOptions": {
77
"sourceType": "script"
8+
},
9+
"rules": {
10+
"strict": [ "error", "global" ],
11+
"consistent-return": "off",
12+
"jsx-a11y/href-no-hash": "off",
13+
"react/jsx-filename-extension": "off",
814
}
915
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@
3232
},
3333
"dependencies": {
3434
"camelize": "^1.0.0",
35+
"eslint-config-airbnb": "^15.1.0",
36+
"eslint-plugin-import": "^2.7.0",
37+
"eslint-plugin-jsx-a11y": "^6.0.2",
38+
"eslint-plugin-react": "^7.3.0",
3539
"except": "^0.1.3",
3640
"front-matter": "^2.1.2",
3741
"node-prismjs": "^0.1.0",
3842
"remarkable": "^1.7.1"
3943
},
4044
"devDependencies": {
4145
"eslint": "^3.19.0",
42-
"eslint-config-fernandopasik": "^0.5.1",
4346
"jest": "^20.0.0",
47+
"react": "^15.6.1",
4448
"watch": "^1.0.2"
4549
},
4650
"engines": {

src/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const camelize = require('camelize');
34
const except = require('except');
45

@@ -16,14 +17,13 @@ const except = require('except');
1617
* @returns {String} - React Component
1718
*/
1819
module.exports = function build(markdown) {
19-
2020
let doImports = 'import React from \'react\';\n';
21-
const
22-
imports = markdown.attributes.imports || {},
23-
jsx = markdown.html.replace(/class=/g, 'className=');
21+
const imports = markdown.attributes.imports || {};
22+
const jsx = markdown.html.replace(/class=/g, 'className=');
2423

2524
const frontMatterAttributes = except(markdown.attributes, 'imports');
2625

26+
// eslint-disable-next-line no-restricted-syntax
2727
for (const variable in imports) {
2828
// eslint-disable-next-line no-prototype-builtins
2929
if (imports.hasOwnProperty(variable)) {

src/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
'use strict';
22

3-
const
4-
build = require('./build.js'),
5-
parser = require('./parser.js');
3+
const build = require('./build.js');
4+
const parser = require('./parser.js');
65

76
/**
87
* Main function
98
* @param {String} content Markdown file content
109
*/
11-
module.exports = function (content) {
12-
10+
module.exports = function loader(content) {
1311
const callback = this.async();
1412

1513
parser
1614
.parse(content)
1715
.then(build)
1816
.then(component => callback(null, component))
1917
.catch(callback);
20-
2118
};

src/parser.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
const
4-
frontMatter = require('front-matter'),
5-
Prism = require('node-prismjs'),
6-
Remarkable = require('remarkable'),
7-
escapeHtml = require('remarkable/lib/common/utils').escapeHtml,
8-
md = new Remarkable();
3+
const frontMatter = require('front-matter');
4+
const Prism = require('node-prismjs');
5+
const Remarkable = require('remarkable');
6+
const escapeHtml = require('remarkable/lib/common/utils').escapeHtml;
7+
8+
const md = new Remarkable();
99

1010
/**
1111
* Wraps the code and jsx in an html component
@@ -42,9 +42,8 @@ function parseCodeBlock(code, lang, langPrefix, highlight) {
4242
codeBlock = highlight(code, lang);
4343
}
4444

45-
const
46-
langClass = !lang ? '' : `${langPrefix}${escape(lang, true)}`,
47-
jsx = code;
45+
const langClass = !lang ? '' : `${langPrefix}${escape(lang, true)}`;
46+
const jsx = code;
4847

4948
codeBlock = codeBlock
5049
.replace(/{/g, '{"{"{')
@@ -84,29 +83,28 @@ function parseMarkdown(markdown) {
8483
const language = Prism.languages[lang] || Prism.languages.autoit;
8584
return Prism.highlight(code, language);
8685
},
87-
xhtmlOut: true
86+
xhtmlOut: true,
8887
};
8988

9089
md.set(options);
9190

92-
md.renderer.rules.fence_custom.render = (tokens, idx, options) => {
91+
md.renderer.rules.fence_custom.render = (tokens, idx, opts) => {
9392
// gets tags applied to fence blocks ```react html
9493
const codeTags = tokens[idx].params.split(/\s+/g);
9594
return parseCodeBlock(
9695
tokens[idx].content,
9796
codeTags[codeTags.length - 1],
98-
options.langPrefix,
99-
options.highlight
97+
opts.langPrefix,
98+
opts.highlight,
10099
);
101100
};
102101

103102
try {
104103
html = md.render(markdown.body);
105-
resolve({ html, attributes: markdown.attributes });
104+
return resolve({ html, attributes: markdown.attributes });
106105
} catch (err) {
107106
return reject(err);
108107
}
109-
110108
});
111109
}
112110

@@ -136,5 +134,5 @@ module.exports = {
136134
parse,
137135
parseCodeBlock,
138136
parseFrontMatter,
139-
parseMarkdown
137+
parseMarkdown,
140138
};

test/build.spec.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
'use strict';
22

3-
const
4-
fs = require('fs'),
5-
path = require('path'),
6-
build = require('../src/build.js'),
7-
parser = require('../src/parser.js');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const build = require('../src/build.js');
6+
const parser = require('../src/parser.js');
87

98
describe('Build Component', () => {
10-
119
let component = '';
1210
const mdFile = path.join(__dirname, './examples/hello-world.md');
1311

14-
beforeAll(done => {
12+
beforeAll((done) => {
1513
fs.readFile(mdFile, 'utf8', (err, data) => {
1614
if (err) {
1715
return done(err);
1816
}
1917

2018
parser
2119
.parse(data)
22-
.then(html => {
20+
.then((html) => {
2321
component = build(html);
2422
done();
2523
})
@@ -39,5 +37,4 @@ describe('Build Component', () => {
3937
it('exports the front-matter attributes', () => {
4038
expect(component).toMatch(/export const attributes = {"testFrontMatter":"hello world"}/);
4139
});
42-
4340
});

test/index.spec.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
'use strict';
22

3-
const
4-
fs = require('fs'),
5-
path = require('path'),
6-
loader = require('../src/index.js');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const loader = require('../src/index.js');
76

87
describe('React Markdown Loader', () => {
9-
108
let mdExample = '';
119
const mdFile = path.join(__dirname, './examples/hello-world.md');
1210

13-
beforeAll(done => {
11+
beforeAll((done) => {
1412
fs.readFile(mdFile, 'utf8', (err, data) => {
1513
if (err) {
1614
return done(err);
@@ -21,14 +19,13 @@ describe('React Markdown Loader', () => {
2119
});
2220
});
2321

24-
it('converts markdown to component', done => {
22+
it('converts markdown to component', (done) => {
2523
// eslint-disable-next-line prefer-reflect
2624
loader.call({
27-
async: err => {
25+
async: (err) => {
2826
expect(err).not.toBeDefined();
2927
done();
30-
}
28+
},
3129
}, mdExample);
3230
});
33-
3431
});

test/parser.spec.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
'use strict';
22

3-
const
4-
fs = require('fs'),
5-
path = require('path'),
6-
parser = require('../src/parser.js');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const parser = require('../src/parser.js');
76

87
describe('Parse Markdown', () => {
9-
108
let mdExample = '';
119
const mdFile = path.join(__dirname, './examples/hello-world.md');
1210

13-
beforeAll(done => {
11+
beforeAll((done) => {
1412
fs.readFile(mdFile, 'utf8', (err, data) => {
1513
if (err) {
1614
return done(err);
@@ -35,9 +33,8 @@ describe('Parse Markdown', () => {
3533
});
3634

3735
it('example code blocks have run and source code', () => {
38-
const
39-
exampleCode = 'example',
40-
result = parser.codeBlockTemplate(exampleCode, exampleCode);
36+
const exampleCode = 'example';
37+
const result = parser.codeBlockTemplate(exampleCode, exampleCode);
4138

4239
expect(result).toEqual(`
4340
<div class="example">
@@ -51,21 +48,20 @@ describe('Parse Markdown', () => {
5148
});
5249

5350
it('parses markdown with live code blocks', () =>
54-
parser.parse(mdExample).then(result => {
51+
parser.parse(mdExample).then((result) => {
5552
expect(result.html).toMatch(/<div class="run"><HelloWorld \/>\s*<Button label="Hello World" \/>\s*<\/div>/);
56-
})
53+
}),
5754
);
5855

5956
it('parses markdown and created valid html for JSX', () =>
60-
parser.parse('![](myImage.png)').then(result => {
57+
parser.parse('![](myImage.png)').then((result) => {
6158
expect(result.html).toMatch(/<p><img src="myImage.png" alt="" \/><\/p>\n/);
62-
})
59+
}),
6360
);
6461

6562
it('provides the front-matter attributes', () =>
66-
parser.parse(mdExample).then(result => {
63+
parser.parse(mdExample).then((result) => {
6764
expect(result.attributes).toHaveProperty('test-front-matter', 'hello world');
68-
})
65+
}),
6966
);
70-
7167
});

0 commit comments

Comments
 (0)