Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: integrate eslint #255

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
// Common settings for JS Files.
extends: [
"eslint:recommended",
"plugin:eslint-comments/recommended",
// Disables all formatting related rules as formatting is handled by prettier, not eslint.
"prettier",
],
parserOptions: {
// Targeting modern nodejs versions
// Consult with: https://kangax.github.io/compat-table/es2016plus/
ecmaVersion: 2018,
},
env: {
commonjs: true,
mocha: true,
node: true,
es6: true,
},
rules: {
"eslint-comments/require-description": ["error", { ignore: [] }],
},
};
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"lerna:version": "lerna version && yarn run cirlce:release",
"cirlce:release": "node ./scripts/trigger-release",
"lerna:publish": "lerna publish from-git --yes",
"ci": "npm-run-all format:validate ci:subpackages coverage:merge legal:*",
"ci": "npm-run-all format:validate lint:validate ci:subpackages coverage:merge legal:*",
"format:fix": "prettier --write --ignore-path .gitignore \"**/*.@(ts|js|json|md)\"",
"format:validate": "prettier --check --ignore-path .gitignore \"**/*.@(ts|js|json|md)\"",
"lint:fix": "eslint . --ext=js --fix --max-warnings=0 --ignore-path=.gitignore",
"lint:validate": "eslint . --ext=js --max-warnings=0 --ignore-path=.gitignore",
"ci:subpackages": "lerna run ci",
"test": "lerna run test",
"coverage": "lerna run coverage",
Expand All @@ -29,6 +31,9 @@
"@types/chai": "4.2.11",
"@types/mocha": "7.0.2",
"@types/node": "10.17.15",
"eslint": "7.9.0",
"eslint-config-prettier": "6.15.0",
"eslint-plugin-eslint-comments": "3.2.0",
"coveralls": "3.1.0",
"make-dir": "3.1.0",
"glob": "7.1.6",
Expand Down Expand Up @@ -64,6 +69,9 @@
"lint-staged": {
"*.{ts,js,md,json}": [
"prettier --write"
],
"*.{ts,js}": [
"eslint --fix --max-warnings=0 --ignore-pattern=!.*"
]
},
"config": {
Expand Down
2 changes: 2 additions & 0 deletions packages/ast/lib/build-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function buildAst(docCst, tokenVector) {
return xmlDocAst;
}

/* eslint-disable no-unused-vars -- consistent signatures in visitor methods even if they are empty placeholders */
class CstToAstVisitor extends BaseXmlCstVisitor {
constructor() {
super();
Expand Down Expand Up @@ -253,6 +254,7 @@ class CstToAstVisitor extends BaseXmlCstVisitor {
// Irrelevant for the AST at this time
}
}
/* eslint-enable no-unused-vars -- see matching disable comment */

const AstBuilder = new CstToAstVisitor();

Expand Down
2 changes: 1 addition & 1 deletion packages/ast/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { values, reduce, has, isArray } = require("lodash");
const { reduce, has, isArray } = require("lodash");

function getAstChildrenReflective(astParent) {
const astChildren = reduce(
Expand Down
6 changes: 2 additions & 4 deletions packages/ast/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ function modifyAstForAssertions(astNode) {
accept(astNode, positionReducerVisitor);
}

function removeParentProps(astNode) {
accept(astNode, parentRemoverVisitor);
}

/**
* @type {XMLAstVisitor}
*/
const parentRemoverVisitor = {
/* eslint-disable-next-line no-unused-vars -- consistent signatures in visitor methods even if they are empty placeholders */
visitXMLDocument: (node) => {
// top level XML Doc does not have a parent...
},
Expand Down Expand Up @@ -85,6 +82,7 @@ function assertParentPropsAreValid(astNode) {
* @type {XMLAstVisitor}
*/
const parentPropsValidatorVisitor = {
/* eslint-disable-next-line no-unused-vars -- consistent signatures in visitor methods even if they are empty placeholders */
visitXMLDocument: (node) => {
// top level XML Doc does not have a parent...
},
Expand Down
2 changes: 2 additions & 0 deletions packages/content-assist/lib/content-assist.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function computeCompletionSyntacticContext({
return contextVisitor.result;
}

/* eslint-disable no-unused-vars -- consistent signatures in visitor methods even if they are empty placeholders */
class SuggestionContextVisitor extends BaseXmlCstVisitor {
constructor(docAst, offset, tokenVector) {
super();
Expand Down Expand Up @@ -171,6 +172,7 @@ class SuggestionContextVisitor extends BaseXmlCstVisitor {
/* istanbul ignore next - place holder*/
misc(ctx, astNode) {}
}
/* eslint-enable no-unused-vars -- see matching pair above */

function handleElementNameWithoutPrefixScenario(ctx, astNode, visitor) {
/* istanbul ignore else - Very difficult to reproduce specific partial CSTs */
Expand Down
1 change: 1 addition & 0 deletions packages/content-assist/test/scenarios-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe("The XML Content Assist Capabilities", () => {
let providerCalled = false;
getSampleSuggestions(sample, {
elementContent: [
// eslint-disable-next-line no-unused-vars -- match the type of `ElementContentCompletion` for consistency
({ element }) => {
providerCalled = true;
},
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ class Parser extends CstParser {
// https://github.com/SAP/chevrotain/issues/1055
/* istanbul ignore next - should be tested as part of Chevrotain */
findReSyncTokenType() {
var allPossibleReSyncTokTypes = this.flattenFollowSet();
const allPossibleReSyncTokTypes = this.flattenFollowSet();
// this loop will always terminate as EOF is always in the follow stack and also always (virtually) in the input
let nextToken = this.LA(1);
let k = 2;
/* eslint-disable-next-line no-constant-condition -- see above comment */
while (true) {
const foundMatch = allPossibleReSyncTokTypes.find((resyncTokType) => {
const canMatch = tokenMatcher(nextToken, resyncTokType);
Expand Down
4 changes: 2 additions & 2 deletions packages/simple-schema/lib/content-assist/attribute-name.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { difference, map, filter } = require("lodash");
const { difference, map } = require("lodash");

/**
* @param {XMLElement} elementNode
* @param {XSSElement} xssElement
*
* @returns {CompletionSuggestion[]}
*/
function attributeNameCompletion(elementNode, xssElement, prefix = "") {
function attributeNameCompletion(elementNode, xssElement) {
const possibleSuggestions = map(xssElement.attributes, (_) => _.key);
const existingAttribNames = map(elementNode.attributes, (_) => _.key);
const possibleNewSuggestions = difference(
Expand Down
38 changes: 18 additions & 20 deletions packages/simple-schema/lib/content-assist/element-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,21 @@ function elementNameCompletion(elementNode, xssElement, prefix = "") {
elementNode.namespaces,
(uri, prefix) => prefix !== DEFAULT_NS
);
const applicableNamespaces = pickBy(
namespacesWithoutDefault,
(uri, prefix) => {
const possibleElements = filter(
xssElement.elements,
(element) =>
has(element, "namespace") === true && element.namespace === uri
);
const possibleSuggestionsWithoutExistingSingular = applicableElements(
xssElement.elements,
elementNode.subElements,
possibleElements
);
const namespaceHasApplicableElements =
possibleSuggestionsWithoutExistingSingular.length > 0;
return namespaceHasApplicableElements;
}
);
const applicableNamespaces = pickBy(namespacesWithoutDefault, (uri) => {
const possibleElements = filter(
xssElement.elements,
(element) =>
has(element, "namespace") === true && element.namespace === uri
);
const possibleSuggestionsWithoutExistingSingular = applicableElements(
xssElement.elements,
elementNode.subElements,
possibleElements
);
const namespaceHasApplicableElements =
possibleSuggestionsWithoutExistingSingular.length > 0;
return namespaceHasApplicableElements;
});
const namespaceSuggestions = map(applicableNamespaces, (uri, prefix) => ({
text: prefix,
label: prefix,
Expand All @@ -87,10 +84,11 @@ function applicableElements(xssElements, subElements, possibleElements) {
const notSingularElemNames = map(notSingularElem, (element) => element.name);
const existingElemNames = map(subElements, (element) => element.name);
const existingSingular = difference(existingElemNames, notSingularElemNames);
return (possibleSuggestionsWithoutExistingSingular = difference(
const possibleSuggestionsWithoutExistingSingular = difference(
allPossibleSuggestions,
existingSingular
));
);
return possibleSuggestionsWithoutExistingSingular;
}

module.exports = {
Expand Down
Loading