Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
icecream17 authored and aminya committed Jul 3, 2022
1 parent de2bda0 commit f178a53
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 166 deletions.
14 changes: 9 additions & 5 deletions packages/language-c/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
exports.activate = function () {
exports.activate = function() {
// Highlight macro bodies as C/C++
for (const language of ['c', 'cpp']) {
for (const nodeType of ['preproc_def', 'preproc_function_def']) {
atom.grammars.addInjectionPoint(`source.${language}`, {
type: nodeType,
language (node) { return language },
content (node) { return node.lastNamedChild }
})
language(node) {
return language;
},
content(node) {
return node.lastNamedChild;
}
});
}
}
}
};
64 changes: 44 additions & 20 deletions packages/language-html/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
exports.activate = function () {
exports.activate = function() {
atom.grammars.addInjectionPoint('text.html.basic', {
type: 'script_element',
language () { return 'javascript' },
content (node) { return node.child(1) }
})
language() {
return 'javascript';
},
content(node) {
return node.child(1);
}
});

atom.grammars.addInjectionPoint('text.html.basic', {
type: 'style_element',
language () { return 'css' },
content (node) { return node.child(1) }
})
language() {
return 'css';
},
content(node) {
return node.child(1);
}
});

atom.grammars.addInjectionPoint('text.html.ejs', {
type: 'template',
language (node) { return 'javascript' },
content (node) { return node.descendantsOfType('code') },
language(node) {
return 'javascript';
},
content(node) {
return node.descendantsOfType('code');
},
newlinesBetween: true
})
});

atom.grammars.addInjectionPoint('text.html.ejs', {
type: 'template',
language (node) { return 'html' },
content (node) { return node.descendantsOfType('content') }
})
language(node) {
return 'html';
},
content(node) {
return node.descendantsOfType('content');
}
});

atom.grammars.addInjectionPoint('text.html.erb', {
type: 'template',
language (node) { return 'ruby' },
content (node) { return node.descendantsOfType('code') },
language(node) {
return 'ruby';
},
content(node) {
return node.descendantsOfType('code');
},
newlinesBetween: true
})
});

atom.grammars.addInjectionPoint('text.html.erb', {
type: 'template',
language (node) { return 'html' },
content (node) { return node.descendantsOfType('content') }
})
}
language(node) {
return 'html';
},
content(node) {
return node.descendantsOfType('content');
}
});
};
43 changes: 21 additions & 22 deletions packages/language-html/spec/tree-sitter-spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const dedent = require('dedent')
const dedent = require('dedent');

describe('Tree-sitter HTML grammar', () => {

beforeEach(async () => {
atom.config.set('core.useTreeSitterParsers', true)
await atom.packages.activatePackage('language-html')
})
atom.config.set('core.useTreeSitterParsers', true);
await atom.packages.activatePackage('language-html');
});

it('tokenizes punctuation in HTML tags and attributes', async () => {
const editor = await atom.workspace.open(`test.html`)
const editor = await atom.workspace.open(`test.html`);

editor.setText(dedent`
<html lang="en">
Expand All @@ -18,64 +17,64 @@ describe('Tree-sitter HTML grammar', () => {
</head>
<body>
</html>
`)
`);

// Tag punctuation.
expect(editor.scopeDescriptorForBufferPosition([0, 0]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.begin'
)
);

expect(editor.scopeDescriptorForBufferPosition([0, 15]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.end'
)
);

expect(editor.scopeDescriptorForBufferPosition([6, 0]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.begin'
)
);

expect(editor.scopeDescriptorForBufferPosition([6, 6]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.end'
)
);

// Attribute-value pair punctuation.
expect(editor.scopeDescriptorForBufferPosition([0, 10]).toString()).toBe(
'.text.html.basic .source.html .punctuation.separator.key-value.html'
)
);

expect(editor.scopeDescriptorForBufferPosition([2, 18]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.begin'
)
);

expect(editor.scopeDescriptorForBufferPosition([2, 24]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.end'
)
);

// Ensure an attribute value delimited by single-quotes won't mark a
// double-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 15]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.begin'
)
);

expect(editor.scopeDescriptorForBufferPosition([3, 16]).toString()).toBe(
'.text.html.basic .source.html .string.html'
)
);

expect(editor.scopeDescriptorForBufferPosition([3, 17]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.end'
)
);

// Ensure an attribute value delimited by double-quotes won't mark a
// single-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 27]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.begin'
)
);

expect(editor.scopeDescriptorForBufferPosition([3, 32]).toString()).toBe(
'.text.html.basic .source.html .string.html'
)
);

expect(editor.scopeDescriptorForBufferPosition([3, 66]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.end'
)
})
})
);
});
});
74 changes: 39 additions & 35 deletions packages/language-javascript/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,86 @@
exports.activate = function () {
if (!atom.grammars.addInjectionPoint) return
exports.activate = function() {
if (!atom.grammars.addInjectionPoint) return;

atom.grammars.addInjectionPoint('source.js', {
type: 'call_expression',

language (callExpression) {
const {firstChild} = callExpression
language(callExpression) {
const { firstChild } = callExpression;
switch (firstChild.type) {
case 'identifier':
return languageStringForTemplateTag(firstChild.text)
return languageStringForTemplateTag(firstChild.text);
case 'call_expression':
return languageStringForTemplateTag(firstChild.children[0].text)
return languageStringForTemplateTag(firstChild.children[0].text);
case 'member_expression':
if (firstChild.startPosition.row === firstChild.endPosition.row) {
return languageStringForTemplateTag(firstChild.text)
return languageStringForTemplateTag(firstChild.text);
}
}
},

content (callExpression) {
const {lastChild} = callExpression
content(callExpression) {
const { lastChild } = callExpression;
if (lastChild.type === 'template_string') {
return lastChild
return lastChild;
}
}
})
});

atom.grammars.addInjectionPoint('source.js', {
type: 'assignment_expression',

language (callExpression) {
const {firstChild} = callExpression
language(callExpression) {
const { firstChild } = callExpression;
if (firstChild.type === 'member_expression') {
if (firstChild.lastChild.text === 'innerHTML') {
return 'html'
return 'html';
}
}
},

content (callExpression) {
const {lastChild} = callExpression
content(callExpression) {
const { lastChild } = callExpression;
if (lastChild.type === 'template_string') {
return lastChild
return lastChild;
}
}
})
});

atom.grammars.addInjectionPoint('source.js', {
type: 'regex_pattern',
language (regex) { return 'regex' },
content (regex) { return regex }
})
language(regex) {
return 'regex';
},
content(regex) {
return regex;
}
});

for (const scopeName of ['source.js', 'source.flow', 'source.ts']) {
atom.grammars.addInjectionPoint(scopeName, {
type: 'comment',
language (comment) {
if (comment.text.startsWith('/**')) return 'jsdoc'
language(comment) {
if (comment.text.startsWith('/**')) return 'jsdoc';
},
content (comment) {
return comment
content(comment) {
return comment;
}
})
});
}
}
};

const CSS_REGEX = /\bstyled\b|\bcss\b/i
const GQL_REGEX = /\bgraphql\b|\bgql\b/i
const SQL_REGEX = /\bsql\b/i
const CSS_REGEX = /\bstyled\b|\bcss\b/i;
const GQL_REGEX = /\bgraphql\b|\bgql\b/i;
const SQL_REGEX = /\bsql\b/i;

function languageStringForTemplateTag (tag) {
function languageStringForTemplateTag(tag) {
if (CSS_REGEX.test(tag)) {
return 'CSS'
return 'CSS';
} else if (GQL_REGEX.test(tag)) {
return 'GraphQL'
return 'GraphQL';
} else if (SQL_REGEX.test(tag)) {
return 'SQL'
return 'SQL';
} else {
return tag
return tag;
}
}
24 changes: 16 additions & 8 deletions packages/language-ruby/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
exports.activate = function() {
if (!atom.grammars.addInjectionPoint) return
if (!atom.grammars.addInjectionPoint) return;

atom.grammars.addInjectionPoint('source.ruby', {
type: 'heredoc_body',
language (node) { return node.lastChild.text },
content (node) { return node }
})
language(node) {
return node.lastChild.text;
},
content(node) {
return node;
}
});

atom.grammars.addInjectionPoint('source.ruby', {
type: 'regex',
language () { return 'regex' },
content (node) { return node }
})
}
language() {
return 'regex';
},
content(node) {
return node;
}
});
};
Loading

0 comments on commit f178a53

Please sign in to comment.