Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Extract HTML hinting into separate chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHenninger committed Feb 19, 2018
1 parent bb8d18f commit c3f2e34
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions packages/builder/src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import './editor-style-overrides.css'
// It would be nice to be able to move it into the
// /vendor directory

import { HTMLHint } from 'htmlhint'


export default class Editor extends React.Component {
editorWillMount(monaco) {
monaco.editor.defineTheme('labjs', {
Expand Down Expand Up @@ -51,30 +48,35 @@ export default class Editor extends React.Component {

// Hook up custom linter (currently only for HTML)
if (this.props.language === 'html') {
model.onDidChangeContent(throttle(() => {
const hints = HTMLHint.verify(
model.getValue(), {
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true,
"attr-unsafe-chars": true
}
).map(hint => ({
startLineNumber: hint.line, startColumn: hint.col,
endLineNumber: hint.line, endColumn: hint.col + hint.raw.length,
message: hint.message,
severity: 1,
}))
// The HTMLHint library loads many dependencies,
// and is not needed directly when the editor
// is first loaded, therefore it is split out here.
import('htmlhint').then(({ HTMLHint }) => {
model.onDidChangeContent(throttle(() => {
const hints = HTMLHint.verify(
model.getValue(), {
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true,
"attr-unsafe-chars": true
}
).map(hint => ({
startLineNumber: hint.line, startColumn: hint.col,
endLineNumber: hint.line, endColumn: hint.col + hint.raw.length,
message: hint.message,
severity: 1,
}))

monaco.editor.setModelMarkers(
model, 'custom-linter', hints
)
}, 500))
monaco.editor.setModelMarkers(
model, 'custom-linter', hints
)
}, 500))
}).catch(e => console.log('Couldn\'t load HTMLHint:', e))
}
}

Expand Down

0 comments on commit c3f2e34

Please sign in to comment.