chore: added new linter config (#1028)

* chore: added new linter config

* chore: linting fixes

* chore: refactore in linting config and minor linting fixes
This commit is contained in:
Anix
2020-02-20 14:01:04 +05:30
committed by GitHub
parent a111df9980
commit 75c72e917b
61 changed files with 2556 additions and 1764 deletions
+55 -45
View File
@@ -1,22 +1,29 @@
/* eslint-disable no-global-assign */
// Load ES6 modules in Node.js on the fly
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
require = require('esm')(
module /* , options */
); /* eslint-disable-line no-global-assign */
const path = require('path')
const { expect } = require('chai')
const path = require('path');
const { expect } = require('chai');
const { JSDOM } = require('jsdom')
const { JSDOM } = require('jsdom');
function ready(callback) {
const state = document.readyState
const state = document.readyState;
if (state === 'complete' || state === 'interactive') {
return setTimeout(callback, 0)
return setTimeout(callback, 0);
}
document.addEventListener('DOMContentLoaded', callback)
document.addEventListener('DOMContentLoaded', callback);
}
module.exports.init = function (fixture = 'default', config = {}, markup = null) {
module.exports.init = function(
fixture = 'default',
config = {},
markup = null
) {
if (markup === null || markup === undefined) {
markup = `<!DOCTYPE html>
<html>
@@ -27,64 +34,67 @@ module.exports.init = function (fixture = 'default', config = {}, markup = null)
window.$docsify = ${JSON.stringify(config, null, 2)}
</script>
</body>
</html>`
</html>`;
}
const rootPath = path.join(__dirname, 'fixtures', fixture)
const rootPath = path.join(__dirname, 'fixtures', fixture);
const dom = new JSDOM(markup)
dom.reconfigure({ url: 'file:///' + rootPath })
const dom = new JSDOM(markup);
dom.reconfigure({ url: 'file:///' + rootPath });
global.window = dom.window
global.document = dom.window.document
global.navigator = dom.window.navigator
global.location = dom.window.location
global.XMLHttpRequest = dom.window.XMLHttpRequest
global.window = dom.window;
global.document = dom.window.document;
global.navigator = dom.window.navigator;
global.location = dom.window.location;
global.XMLHttpRequest = dom.window.XMLHttpRequest;
// Mimic src/core/index.js but for Node.js
function Docsify() {
this._init()
this._init();
}
const proto = Docsify.prototype
const proto = Docsify.prototype;
const { initMixin } = require('../src/core/init')
const { routerMixin } = require('../src/core//router')
const { renderMixin } = require('../src/core//render')
const { fetchMixin } = require('../src/core/fetch')
const { eventMixin } = require('../src/core//event')
const { initMixin } = require('../src/core/init');
const { routerMixin } = require('../src/core//router');
const { renderMixin } = require('../src/core//render');
const { fetchMixin } = require('../src/core/fetch');
const { eventMixin } = require('../src/core//event');
initMixin(proto)
routerMixin(proto)
renderMixin(proto)
fetchMixin(proto)
eventMixin(proto)
initMixin(proto);
routerMixin(proto);
renderMixin(proto);
fetchMixin(proto);
eventMixin(proto);
const NOT_INIT_PATTERN = '<!--main-->'
const NOT_INIT_PATTERN = '<!--main-->';
return new Promise(resolve => {
ready(() => {
const docsify = new Docsify()
const docsify = new Docsify();
// NOTE: I was not able to get it working with a callback, but polling works usually at the first time
const id = setInterval(() => {
if (dom.window.document.body.innerHTML.indexOf(NOT_INIT_PATTERN) === -1) {
clearInterval(id)
if (
dom.window.document.body.innerHTML.indexOf(NOT_INIT_PATTERN) === -1
) {
clearInterval(id);
return resolve({
docsify: docsify,
dom: dom
})
dom: dom,
});
}
}, 10)
})
})
}
}, 10);
});
});
};
module.exports.expectSameDom = function (actual, expected) {
const WHITESPACES_BETWEEN_TAGS = />(\s\s+)</g
module.exports.expectSameDom = function(actual, expected) {
const WHITESPACES_BETWEEN_TAGS = />(\s\s+)</g;
function replacer(match, group1) {
return match.replace(group1, '')
return match.replace(group1, '');
}
expect(actual.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim())
.equal(expected.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim())
}
expect(actual.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim()).equal(
expected.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim()
);
};
+7 -7
View File
@@ -1,9 +1,9 @@
const { init } = require('../_helper')
// const { init } = require('../_helper');
describe('full docsify initialization', function () {
it('TODO: check generated markup', async function () {
const { dom } = await init('simple', { loadSidebar: true })
console.log(dom.window.document.body.innerHTML)
describe('full docsify initialization', function() {
it('TODO: check generated markup', async function() {
// const { dom } = await init('simple', { loadSidebar: true });
// console.log(dom.window.document.body.innerHTML);
// TODO: add some expectations
})
})
});
});
+7 -7
View File
@@ -1,9 +1,9 @@
const { init } = require('../_helper')
const { init } = require('../_helper');
describe('router', function () {
it('TODO: trigger to load another page', async function () {
await init()
window.location = '/?foo=bar'
describe('router', function() {
it('TODO: trigger to load another page', async function() {
await init();
window.location = '/?foo=bar';
// TODO: add some expectations
})
})
});
});
+36 -33
View File
@@ -1,61 +1,64 @@
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
const { expect } = require('chai')
const { History } = require('../../src/core/router/history/base')
/* eslint-disable no-global-assign */
require = require('esm')(
module /* , options */
); /* eslint-disable-line no-global-assign */
const { History } = require('../../src/core/router/history/base');
const { expect } = require('chai');
class MockHistory extends History {
parse(path) {
return { path }
return { path };
}
}
describe('router/history/base', function () {
describe('relativePath true', function () {
var history
describe('router/history/base', function() {
describe('relativePath true', function() {
let history;
beforeEach(function () {
history = new MockHistory({ relativePath: true })
})
beforeEach(function() {
history = new MockHistory({ relativePath: true });
});
it('toURL', function () {
it('toURL', function() {
// WHEN
const url = history.toURL('guide.md', {}, '/zh-ch/')
const url = history.toURL('guide.md', {}, '/zh-ch/');
// THEN
expect(url).equal('/zh-ch/guide')
})
expect(url).equal('/zh-ch/guide');
});
it('toURL with double dot', function () {
it('toURL with double dot', function() {
// WHEN
const url = history.toURL('../README.md', {}, '/zh-ch/')
const url = history.toURL('../README.md', {}, '/zh-ch/');
// THEN
expect(url).equal('/README')
})
expect(url).equal('/README');
});
it('toURL child path', function () {
it('toURL child path', function() {
// WHEN
const url = history.toURL('config/example.md', {}, '/zh-ch/')
const url = history.toURL('config/example.md', {}, '/zh-ch/');
// THEN
expect(url).equal('/zh-ch/config/example')
})
expect(url).equal('/zh-ch/config/example');
});
it('toURL absolute path', function () {
it('toURL absolute path', function() {
// WHEN
const url = history.toURL('/README', {}, '/zh-ch/')
const url = history.toURL('/README', {}, '/zh-ch/');
// THEN
expect(url).equal('/README')
})
})
expect(url).equal('/README');
});
});
it('toURL without relative path', function () {
const history = new MockHistory({ relativePath: false })
it('toURL without relative path', function() {
const history = new MockHistory({ relativePath: false });
// WHEN
const url = history.toURL('README', {}, '/zh-ch/')
const url = history.toURL('README', {}, '/zh-ch/');
// THEN
expect(url).equal('/README')
})
})
expect(url).equal('/README');
});
});
+226 -141
View File
@@ -1,78 +1,93 @@
const { expect } = require('chai')
const { init, expectSameDom } = require('../_helper');
const { expect } = require('chai');
const { init, expectSameDom } = require('../_helper')
describe('render', function() {
it('important content (tips)', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('!> **Time** is money, my friend!');
expect(output).equal(
'<p class="tip"><strong>Time</strong> is money, my friend!</p>'
);
});
describe('render', function () {
it('important content (tips)', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('!> **Time** is money, my friend!')
expect(output).equal('<p class="tip"><strong>Time</strong> is money, my friend!</p>')
})
describe('lists', function () {
it('as unordered task list', async function () {
const { docsify } = await init()
describe('lists', function() {
it('as unordered task list', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(`
- [x] Task 1
- [ ] Task 2
- [ ] Task 3`)
expect(output, `<ul class="task-list">
- [ ] Task 3`);
expect(
output,
`<ul class="task-list">
<li class="task-list-item"><label><input checked="" disabled="" type="checkbox"> Task 1</label></li>
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 2</label></li>
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 3</label></li>
</ul>`)
})
</ul>`
);
});
it('as ordered task list', async function () {
const { docsify } = await init()
it('as ordered task list', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(`
1. [ ] Task 1
2. [x] Task 2`)
expectSameDom(output, `<ol class="task-list">
2. [x] Task 2`);
expectSameDom(
output,
`<ol class="task-list">
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 1</label></li>
<li class="task-list-item"><label><input checked="" disabled="" type="checkbox"> Task 2</label></li>
</ol>`)
})
</ol>`
);
});
it('normal unordered', async function () {
const { docsify } = await init()
it('normal unordered', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(`
- [linktext](link)
- just text`)
expectSameDom(output, `<ul >
- just text`);
expectSameDom(
output,
`<ul >
<li><a href="#/link" >linktext</a></li>
<li>just text</li>
</ul>`)
})
</ul>`
);
});
it('unordered with custom start', async function () {
const { docsify } = await init()
it('unordered with custom start', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(`
1. first
2. second
text
3. third`)
expectSameDom(output, `<ol >
3. third`);
expectSameDom(
output,
`<ol >
<li>first</li>
<li>second</li>
</ol>
<p>text</p>
<ol start="3">
<li>third</li>
</ol>`)
})
</ol>`
);
});
it('nested', async function () {
const { docsify } = await init()
it('nested', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(`
- 1
- 2
- 2 a
- 2 b
- 3`)
expectSameDom(output, `<ul >
- 3`);
expectSameDom(
output,
`<ul >
<li>1</li>
<li>2<ul >
<li>2 a</li>
@@ -80,158 +95,228 @@ text
</ul>
</li>
<li>3</li>
</ul>`)
})
})
</ul>`
);
});
});
describe('image', function () {
it('regular', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl)')
describe('image', function() {
it('regular', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('![alt text](http://imageUrl)');
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" /></p>')
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" /></p>'
);
});
it('class', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl \':class=someCssClass\')')
it('class', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"![alt text](http://imageUrl ':class=someCssClass')"
);
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" class="someCssClass" /></p>')
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" class="someCssClass" /></p>'
);
});
it('id', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl \':id=someCssID\')')
it('id', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"![alt text](http://imageUrl ':id=someCssID')"
);
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" id="someCssID" /></p>')
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" id="someCssID" /></p>'
);
});
it('no-zoom', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl \':no-zoom\')')
it('no-zoom', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"![alt text](http://imageUrl ':no-zoom')"
);
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" data-no-zoom /></p>')
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" data-no-zoom /></p>'
);
});
describe('size', function () {
it('width and height', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl \':size=WIDTHxHEIGHT\')')
describe('size', function() {
it('width and height', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"![alt text](http://imageUrl ':size=WIDTHxHEIGHT')"
);
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" width="WIDTH" height="HEIGHT" /></p>')
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" width="WIDTH" height="HEIGHT" /></p>'
);
});
it('width', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('![alt text](http://imageUrl \':size=50\')')
it('width', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"![alt text](http://imageUrl ':size=50')"
);
expectSameDom(output, '<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" width="50" height="50" /></p>')
})
})
})
expectSameDom(
output,
'<p><img src="http://imageUrl" data-origin="http://imageUrl" alt="alt text" width="50" height="50" /></p>'
);
});
});
});
describe('heading', function () {
it('h1', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('# h1 tag')
expectSameDom(output, `
describe('heading', function() {
it('h1', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('# h1 tag');
expectSameDom(
output,
`
<h1 id="h1-tag">
<a href="#/?id=h1-tag" data-id="h1-tag" class="anchor">
<span>h1 tag</span>
</a>
</h1>`)
})
</h1>`
);
});
it('h2', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('## h2 tag')
expectSameDom(output, `
it('h2', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('## h2 tag');
expectSameDom(
output,
`
<h2 id="h2-tag">
<a href="#/?id=h2-tag" data-id="h2-tag" class="anchor">
<span>h2 tag</span>
</a>
</h2>`)
})
</h2>`
);
});
it('h3', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('### h3 tag')
expectSameDom(output, `
it('h3', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('### h3 tag');
expectSameDom(
output,
`
<h3 id="h3-tag">
<a href="#/?id=h3-tag" data-id="h3-tag" class="anchor">
<span>h3 tag</span>
</a>
</h3>`)
})
</h3>`
);
});
it('h4', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('#### h4 tag')
expectSameDom(output, `
it('h4', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('#### h4 tag');
expectSameDom(
output,
`
<h4 id="h4-tag">
<a href="#/?id=h4-tag" data-id="h4-tag" class="anchor">
<span>h4 tag</span>
</a>
</h4>`)
})
</h4>`
);
});
it('h5', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('##### h5 tag')
expectSameDom(output, `
it('h5', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('##### h5 tag');
expectSameDom(
output,
`
<h5 id="h5-tag">
<a href="#/?id=h5-tag" data-id="h5-tag" class="anchor">
<span>h5 tag</span>
</a>
</h5>`)
})
</h5>`
);
});
it('h6', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('###### h6 tag')
expectSameDom(output, `
it('h6', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('###### h6 tag');
expectSameDom(
output,
`
<h6 id="h6-tag">
<a href="#/?id=h6-tag" data-id="h6-tag" class="anchor">
<span>h6 tag</span>
</a>
</h6>`)
})
})
</h6>`
);
});
});
describe('link', function () {
it('regular', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('[alt text](http://url)')
describe('link', function() {
it('regular', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile('[alt text](http://url)');
expectSameDom(output, '<p><a href="http://url" target="_blank">alt text</a></p>')
})
expectSameDom(
output,
'<p><a href="http://url" target="_blank">alt text</a></p>'
);
});
it('disabled', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('[alt text](http://url \':disabled\')')
it('disabled', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"[alt text](http://url ':disabled')"
);
expectSameDom(output, '<p><a href="javascript:void(0)" target="_blank" disabled>alt text</a></p>')
})
expectSameDom(
output,
'<p><a href="javascript:void(0)" target="_blank" disabled>alt text</a></p>'
);
});
it('target', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('[alt text](http://url \':target=_self\')')
it('target', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"[alt text](http://url ':target=_self')"
);
expectSameDom(output, '<p><a href="http://url" target="_blank" target="_self">alt text</a></p>')
})
expectSameDom(
output,
'<p><a href="http://url" target="_blank" target="_self">alt text</a></p>'
);
});
it('class', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('[alt text](http://url \':class=someCssClass\')')
it('class', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"[alt text](http://url ':class=someCssClass')"
);
expectSameDom(output, '<p><a href="http://url" target="_blank" class="someCssClass">alt text</a></p>')
})
expectSameDom(
output,
'<p><a href="http://url" target="_blank" class="someCssClass">alt text</a></p>'
);
});
it('id', async function () {
const { docsify } = await init()
const output = docsify.compiler.compile('[alt text](http://url \':id=someCssID\')')
it('id', async function() {
const { docsify } = await init();
const output = docsify.compiler.compile(
"[alt text](http://url ':id=someCssID')"
);
expectSameDom(output, '<p><a href="http://url" target="_blank" id="someCssID">alt text</a></p>')
})
})
})
expectSameDom(
output,
'<p><a href="http://url" target="_blank" id="someCssID">alt text</a></p>'
);
});
});
});
+20 -17
View File
@@ -1,29 +1,32 @@
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
const { expect } = require('chai')
const { resolvePath } = require('../../src/core/router/util')
/* eslint-disable no-global-assign */
require = require('esm')(
module /* , options */
); /* eslint-disable-line no-global-assign */
const { resolvePath } = require('../../src/core/router/util');
const { expect } = require('chai');
describe('router/util', function () {
it('resolvePath', async function () {
describe('router/util', function() {
it('resolvePath', async function() {
// WHEN
const result = resolvePath('hello.md')
const result = resolvePath('hello.md');
// THEN
expect(result).equal('/hello.md')
})
expect(result).equal('/hello.md');
});
it('resolvePath with dot', async function () {
it('resolvePath with dot', async function() {
// WHEN
const result = resolvePath('./hello.md')
const result = resolvePath('./hello.md');
// THEN
expect(result).equal('/hello.md')
})
expect(result).equal('/hello.md');
});
it('resolvePath with two dots', async function () {
it('resolvePath with two dots', async function() {
// WHEN
const result = resolvePath('test/../hello.md')
const result = resolvePath('test/../hello.md');
// THEN
expect(result).equal('/hello.md')
})
})
expect(result).equal('/hello.md');
});
});