Commit d14eac31 authored by Guillaume Grossetie's avatar Guillaume Grossetie 🎧
Browse files

add eslint (JavaScript)

parent c678fe29
......@@ -5,13 +5,10 @@ const litePreset = require('cssnano-preset-lite')
const cssnanoPreset = litePreset({ discardComments: false })
const ospath = require('path')
const asciidoctor = require('@asciidoctor/core')()
const documentModelConverter = require(`${__dirname}/lib/document-model-converter.js`)
const autoprefixer = require('autoprefixer')
const postcss = require('postcss')
const postcssPresetEnv = require('postcss-preset-env')
const postcssAtImport = require("postcss-import")
const fs = require('fs')
const path = require('path')
const postcssAtImport = require('postcss-import')
module.exports = function (eleventyConfig, rest) {
eleventyConfig.addPassthroughCopy('pages/**/*.{jpg,png,gif,svg,ico,txt,json}')
......@@ -22,42 +19,41 @@ module.exports = function (eleventyConfig, rest) {
eleventyConfig.addExtension('css', {
outputFileExtension: 'css',
compileOptions: {
cache: false,
cache: false
},
compile: async function (inputContent, inputPath) {
const parsed = path.parse(inputPath)
if (parsed.name.startsWith("_")) {
const parsed = ospath.parse(inputPath)
if (parsed.name.startsWith('_')) {
return
}
const result = await postcss([
postcssAtImport,
autoprefixer,
postcssPresetEnv({ browsers: 'defaults,not IE 11' }),
cssnano({ preset: cssnanoPreset})
cssnano({ preset: cssnanoPreset })
])
.process(inputContent, { from: inputPath, to: '_site/assets/css/main.css' })
return async (data) => {
return async () => {
return result.css
}
}
})
eleventyConfig.addExtension('adoc', {
compile: function (fileContents, path) {
return function (data) {
compile: function (inputContent) {
return function () {
const registry = asciidoctor.Extensions.create()
const documentModel = asciidoctor.convert(fileContents, {
return asciidoctor.convert(inputContent, {
safe: 'unsafe',
extension_registry: registry,
template_dirs: ospath.join(__dirname, 'templates'),
attributes: {
'skip-front-matter': '',
'showtitle': '',
showtitle: '',
'syntax-highlighter': 'highlight.js',
'includedir': `${__dirname}/pages/examples`
includedir: ospath.join(__dirname, 'pages', 'examples')
},
backend: 'json'
})
return documentModel
}
}
})
......@@ -68,7 +64,7 @@ module.exports = function (eleventyConfig, rest) {
input: 'pages',
includes: '_includes',
layouts: '_layouts',
data: '_data',
},
data: '_data'
}
}
}
!.eleventy.js
{
"extends": "standard"
}
This diff is collapsed.
......@@ -4,7 +4,9 @@
"version": "1.0.0",
"license": "EPL-2.0",
"scripts": {
"lint": "stylelint 'pages/assets/**/*.css'",
"lint": "npm run lint:js && npm run lint:css",
"lint:js": "eslint .eleventy.js rollup.config.js pages/assets/js/**.js",
"lint:css": "stylelint 'pages/assets/**/*.css'",
"build": "rollup -c --environment BUILD:production && eleventy --config .eleventy.js",
"start": "rollup -c -w & eleventy --serve --config .eleventy.js"
},
......@@ -23,6 +25,8 @@
"@rollup/plugin-node-resolve": "^13.1.3",
"cssnano": "^5.0.17",
"cssnano-preset-lite": "^2.0.3",
"eslint": "^8.9.0",
"eslint-config-standard": "^17.0.0-1",
"highlight.js": "^9.18.3",
"highlightjs-line-numbers.js": "^2.8.0",
"node-html-parser": "^5.2.0",
......
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M0 219.2v212.5c0 14.25 11.62 26.25 26.5 27C75.32 461.2 180.2 471.3 240 511.9V245.2C181.4 205.5 79.99 194.8 29.84 192C13.59 191.1 0 203.6 0 219.2zM482.2 192c-50.09 2.848-151.3 13.47-209.1 53.09C272.1 245.2 272 245.3 272 245.5v266.5c60.04-40.39 164.7-50.76 213.5-53.28C500.4 457.9 512 445.9 512 431.7V219.2C512 203.6 498.4 191.1 482.2 192zM352 96c0-53-43-96-96-96S160 43 160 96s43 96 96 96S352 149 352 96z"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M512 448H64c-35.35 0-64-28.65-64-64V128c0-35.35 28.65-64 64-64h448c35.35 0 64 28.65 64 64v256C576 419.3 547.3 448 512 448zM128 180v-40C128 133.4 122.6 128 116 128h-40C69.38 128 64 133.4 64 140v40C64 186.6 69.38 192 76 192h40C122.6 192 128 186.6 128 180zM224 180v-40C224 133.4 218.6 128 212 128h-40C165.4 128 160 133.4 160 140v40C160 186.6 165.4 192 172 192h40C218.6 192 224 186.6 224 180zM320 180v-40C320 133.4 314.6 128 308 128h-40C261.4 128 256 133.4 256 140v40C256 186.6 261.4 192 268 192h40C314.6 192 320 186.6 320 180zM416 180v-40C416 133.4 410.6 128 404 128h-40C357.4 128 352 133.4 352 140v40C352 186.6 357.4 192 364 192h40C410.6 192 416 186.6 416 180zM512 180v-40C512 133.4 506.6 128 500 128h-40C453.4 128 448 133.4 448 140v40C448 186.6 453.4 192 460 192h40C506.6 192 512 186.6 512 180zM128 276v-40C128 229.4 122.6 224 116 224h-40C69.38 224 64 229.4 64 236v40C64 282.6 69.38 288 76 288h40C122.6 288 128 282.6 128 276zM224 276v-40C224 229.4 218.6 224 212 224h-40C165.4 224 160 229.4 160 236v40C160 282.6 165.4 288 172 288h40C218.6 288 224 282.6 224 276zM320 276v-40C320 229.4 314.6 224 308 224h-40C261.4 224 256 229.4 256 236v40C256 282.6 261.4 288 268 288h40C314.6 288 320 282.6 320 276zM416 276v-40C416 229.4 410.6 224 404 224h-40C357.4 224 352 229.4 352 236v40C352 282.6 357.4 288 364 288h40C410.6 288 416 282.6 416 276zM512 276v-40C512 229.4 506.6 224 500 224h-40C453.4 224 448 229.4 448 236v40C448 282.6 453.4 288 460 288h40C506.6 288 512 282.6 512 276zM128 372v-40C128 325.4 122.6 320 116 320h-40C69.38 320 64 325.4 64 332v40C64 378.6 69.38 384 76 384h40C122.6 384 128 378.6 128 372zM416 372v-40C416 325.4 410.6 320 404 320h-232C165.4 320 160 325.4 160 332v40C160 378.6 165.4 384 172 384h232C410.6 384 416 378.6 416 372zM512 372v-40C512 325.4 506.6 320 500 320h-40C453.4 320 448 325.4 448 332v40C448 378.6 453.4 384 460 384h40C506.6 384 512 378.6 512 372z"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M248.8 4.994C249.9 1.99 252.8 .0001 256 .0001C259.2 .0001 262.1 1.99 263.2 4.994L277.3 42.67L315 56.79C318 57.92 320 60.79 320 64C320 67.21 318 70.08 315 71.21L277.3 85.33L263.2 123C262.1 126 259.2 128 256 128C252.8 128 249.9 126 248.8 123L234.7 85.33L196.1 71.21C193.1 70.08 192 67.21 192 64C192 60.79 193.1 57.92 196.1 56.79L234.7 42.67L248.8 4.994zM427.4 14.06C446.2-4.686 476.6-4.686 495.3 14.06L529.9 48.64C548.6 67.38 548.6 97.78 529.9 116.5L148.5 497.9C129.8 516.6 99.38 516.6 80.64 497.9L46.06 463.3C27.31 444.6 27.31 414.2 46.06 395.4L427.4 14.06zM461.4 59.31L356.3 164.3L379.6 187.6L484.6 82.58L461.4 59.31zM7.491 117.2L64 96L85.19 39.49C86.88 34.98 91.19 32 96 32C100.8 32 105.1 34.98 106.8 39.49L128 96L184.5 117.2C189 118.9 192 123.2 192 128C192 132.8 189 137.1 184.5 138.8L128 160L106.8 216.5C105.1 221 100.8 224 96 224C91.19 224 86.88 221 85.19 216.5L64 160L7.491 138.8C2.985 137.1 0 132.8 0 128C0 123.2 2.985 118.9 7.491 117.2zM359.5 373.2L416 352L437.2 295.5C438.9 290.1 443.2 288 448 288C452.8 288 457.1 290.1 458.8 295.5L480 352L536.5 373.2C541 374.9 544 379.2 544 384C544 388.8 541 393.1 536.5 394.8L480 416L458.8 472.5C457.1 477 452.8 480 448 480C443.2 480 438.9 477 437.2 472.5L416 416L359.5 394.8C354.1 393.1 352 388.8 352 384C352 379.2 354.1 374.9 359.5 373.2z"/></svg>
\ No newline at end of file
......@@ -6,7 +6,7 @@ import { standardKeymap } from '@codemirror/commands'
import { history, historyKeymap } from '@codemirror/history'
import hljs from 'highlight.js'
export function init() {
export function init () {
const processor = Asciidoctor()
const input = `= Hello, AsciiDoc!
......@@ -46,7 +46,7 @@ puts 'Hello, World!'
const view = new EditorView({ state })
editor.appendChild(view.dom)
function convertToHtml() {
function convertToHtml () {
editorPreview.innerHTML = processor.convert(view.state.doc.text, {
attributes: { showtitle: '', icons: 'font' }
})
......@@ -55,7 +55,7 @@ puts 'Hello, World!'
})
}
function debounce(func, duration) {
function debounce (func, duration) {
let timeout
return function (...args) {
const effect = () => {
......
import hljs from "highlight.js/lib/highlight.js"
import xmlLanguage from "highlight.js/lib/languages/xml.js"
import asciidocLanguage from "highlight.js/lib/languages/asciidoc.js"
import markdownLanguage from "highlight.js/lib/languages/markdown.js"
import rubyLanguage from "highlight.js/lib/languages/ruby.js"
import hljs from 'highlight.js/lib/highlight.js'
import xmlLanguage from 'highlight.js/lib/languages/xml.js'
import asciidocLanguage from 'highlight.js/lib/languages/asciidoc.js'
import markdownLanguage from 'highlight.js/lib/languages/markdown.js'
import rubyLanguage from 'highlight.js/lib/languages/ruby.js'
import initHljsNumbers from 'highlightjs-line-numbers.js'
export function init() {
export function init () {
hljs.registerLanguage('asciidoc', asciidocLanguage)
hljs.registerLanguage('xml', xmlLanguage)
hljs.registerLanguage('markdown', markdownLanguage)
hljs.registerLanguage('ruby', rubyLanguage)
initHljsNumbers(hljs)
hljs.registerLanguage("rst", function (e) {
hljs.registerLanguage('rst', function (e) {
return {}
})
......
export function init() {
export function init () {
const hash = window.location.hash
find('.tabset').forEach(function (tabset) {
let active
......@@ -10,7 +9,7 @@ export function init() {
const id = (tab.querySelector('a[id]') || tab).id
if (!id) return
const pane = getPane(id, tabset)
if (!idx) first = { tab: tab, pane: pane }
if (!idx) first = { tab, pane }
if (!active && hash === '#' + id && (active = true)) {
tab.classList.add('is-active')
if (pane) pane.classList.add('is-active')
......@@ -18,7 +17,7 @@ export function init() {
tab.classList.remove('is-active')
if (pane) pane.classList.remove('is-active')
}
tab.addEventListener('click', activateTab.bind({ tabset: tabset, tab: tab, pane: pane, id: id }))
tab.addEventListener('click', activateTab.bind({ tabset, tab, pane, id }))
})
if (!active && first) {
first.tab.classList.add('is-active')
......@@ -34,13 +33,13 @@ export function init() {
const anchor = document.getElementById(id)
const tab = anchor.parentElement.parentElement
const pane = getPane(id, tabset)
activateTab.bind({ tabset: tabset, tab: tab, pane: pane, id: id })(event)
activateTab.bind({ tabset, tab, pane, id })(event)
})
}
tabset.classList.remove('is-loading')
})
function activateTab(e) {
function activateTab (e) {
const tab = this.tab
const pane = this.pane
const id = this.id
......@@ -60,11 +59,11 @@ export function init() {
e.preventDefault()
}
function find(selector, from) {
function find (selector, from) {
return Array.prototype.slice.call((from || document).querySelectorAll(selector))
}
function getPane(id, tabset) {
function getPane (id, tabset) {
return find('.tab-pane', tabset).find(function (it) {
return it.getAttribute('aria-labelledby') === id
})
......
export function init() {
export function init () {
find('.toggleset').forEach(function (toggleset) {
find(':scope > .toggle > a', toggleset).forEach(function (item) {
item.addEventListener('click', function(event) {
item.addEventListener('click', function (event) {
find(':scope > .toggle > a', toggleset).forEach(function (it) {
it === item ? it.classList.add('is-active') : it.classList.remove('is-active')
})
......
import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import { terser } from "rollup-plugin-terser"
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import { babel } from '@rollup/plugin-babel'
function wrap() {
function wrap () {
return {
name: 'rollup-plugin-wrap',
transform(content, id) {
transform (content, id) {
if (id.endsWith('highlightjs-line-numbers.js/src/highlightjs-line-numbers.js')) {
content = `export default function init(hljs) {
window.hljs = hljs
;${content}
}`;
}`
return {
code: content,
map: { mappings: '' }
}
}
return null;
return null
}
}
}
export default {
input: "pages/assets/js/main.js",
input: 'pages/assets/js/main.js',
output: {
file: "_site/assets/js/main.bundle.js",
format: "iife",
file: '_site/assets/js/main.bundle.js',
format: 'iife',
strict: false // Opal does not work in strict mode :|
},
plugins: [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment