Skip to content

Commit c288930

Browse files
committed
Re-enabling Husky and adjusting linter/prettier settings
1 parent 87def39 commit c288930

File tree

5 files changed

+31
-82
lines changed

5 files changed

+31
-82
lines changed

.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"extends": ["eslint:recommended", "prettier"],
1818
"rules": {
19-
"prettier/prettier": "error",
2019
"no-console": ["error", { "allow": ["warn"] }],
2120
"linebreak-style": ["error", "unix"],
22-
"guard-for-in": "error"
21+
"guard-for-in": "error",
22+
"max-len": "off"
2323
}
2424
}

.prettierrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
singleQuote: true
2-
jsxBracketSameLine: true
32
semi: false
43
trailingComma: all
4+
printWidth: 120

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"scripts": {
1414
"lint": "./node_modules/eslint/bin/eslint.js ./**/*.js",
1515
"test": "./node_modules/.bin/jest",
16-
"coverage": "./node_modules/.bin/jest --coverage"
16+
"coverage": "./node_modules/.bin/jest --coverage",
17+
"prepare": "husky install"
1718
},
1819
"contributors": [
1920
"Alexander Jones",
@@ -38,7 +39,7 @@
3839
"eslint": "^8.15.0",
3940
"eslint-config-prettier": "^8.5.0",
4041
"eslint-plugin-prettier": "^4.0.0",
41-
"husky": "^8.0.1",
42+
"husky": "^8.0.0",
4243
"jest": "^28.1.0",
4344
"jest-environment-node": "^28.1.0",
4445
"prettier": "^2.6.2",

validator/stringParser.js

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,24 @@ const utils = require('../utils')
22
const { hedStringIsAGroup, removeGroupParentheses } = require('../utils/hed')
33
const { generateIssue } = require('../common/issues/issues')
44

5-
const {
6-
ParsedHedTag,
7-
ParsedHed2Tag,
8-
ParsedHed3Tag,
9-
ParsedHedGroup,
10-
ParsedHedString,
11-
} = require('./types/parsedHed')
5+
const { ParsedHedTag, ParsedHed2Tag, ParsedHed3Tag, ParsedHedGroup, ParsedHedString } = require('./types/parsedHed')
126

137
const openingGroupCharacter = '('
148
const closingGroupCharacter = ')'
159
const delimiters = new Set([','])
1610

1711
/**
18-
* Split a full HED string into tags.
12+
* Split a HED string into tags.
1913
*
20-
* @param {string} hedString The full HED string.
14+
* @param {string} hedString The HED string to be split.
2115
* @param {Schemas} hedSchemas The collection of HED schemas.
22-
* @param {int} groupStartingIndex The start index of the group in the full HED string.
23-
* @returns {[ParsedHedTag[], object<string, Issue[]>]} An array of HED tags (top-level relative to the passed string) and any issues found.
16+
* @param {int} groupStartingIndex The start index of the containing group in the full HED string.
17+
* @returns {[ParsedHedTag[], Object<string, Issue[]>]} An array of HED tags (top-level relative to the passed string) and any issues found.
2418
*/
25-
const splitHedString = function (
26-
hedString,
27-
hedSchemas,
28-
groupStartingIndex = 0,
29-
) {
30-
const doubleQuoteCharacter = '"'
19+
const splitHedString = function (hedString, hedSchemas, groupStartingIndex = 0) {
3120
const colonCharacter = ':'
3221
const slashCharacter = '/'
33-
const invalidCharacters = ['{', '}', '[', ']', '~']
22+
const invalidCharacters = ['{', '}', '[', ']', '~', '"']
3423

3524
const hedTags = []
3625
const conversionIssues = []
@@ -89,10 +78,7 @@ const splitHedString = function (
8978
resetStartingIndex = false
9079
}
9180
const character = hedString.charAt(i)
92-
if (character === doubleQuoteCharacter) {
93-
// Skip double quotes
94-
continue
95-
} else if (character === openingGroupCharacter) {
81+
if (character === openingGroupCharacter) {
9682
// Count group characters
9783
groupDepth++
9884
} else if (character === closingGroupCharacter) {
@@ -141,14 +127,9 @@ const splitHedString = function (
141127
* @param {Schemas} hedSchemas The collection of HED schemas.
142128
* @param {ParsedHedString} parsedString The object to store parsed output in.
143129
* @param {boolean} isTopLevel Whether these tag groups are at the top level.
144-
* @return {object<string, Issue[]>[]} The array of issues.
130+
* @return {Object<string, Issue[]>[]} The array of issues.
145131
*/
146-
const findTagGroups = function (
147-
groupTagsList,
148-
hedSchemas,
149-
parsedString,
150-
isTopLevel,
151-
) {
132+
const findTagGroups = function (groupTagsList, hedSchemas, parsedString, isTopLevel) {
152133
const issues = []
153134
const copiedGroupTagsList = groupTagsList.slice()
154135
copiedGroupTagsList.forEach((tagOrGroup, index) => {
@@ -160,12 +141,7 @@ const findTagGroups = function (
160141
hedSchemas,
161142
tagOrGroup.originalBounds[0] + 1,
162143
)
163-
const nestedIssues = findTagGroups(
164-
nestedGroupTagList,
165-
hedSchemas,
166-
parsedString,
167-
false,
168-
)
144+
const nestedIssues = findTagGroups(nestedGroupTagList, hedSchemas, parsedString, false)
169145
groupTagsList[index] = new ParsedHedGroup(
170146
tagOrGroup.originalTag,
171147
nestedGroupTagList,
@@ -246,14 +222,8 @@ const substituteCharacters = function (hedString) {
246222
*/
247223
const countTagGroupParentheses = function (hedString) {
248224
const issues = []
249-
const numberOfOpeningParentheses = utils.string.getCharacterCount(
250-
hedString,
251-
openingGroupCharacter,
252-
)
253-
const numberOfClosingParentheses = utils.string.getCharacterCount(
254-
hedString,
255-
closingGroupCharacter,
256-
)
225+
const numberOfOpeningParentheses = utils.string.getCharacterCount(hedString, openingGroupCharacter)
226+
const numberOfClosingParentheses = utils.string.getCharacterCount(hedString, closingGroupCharacter)
257227
if (numberOfOpeningParentheses !== numberOfClosingParentheses) {
258228
issues.push(
259229
generateIssue('parentheses', {
@@ -268,16 +238,10 @@ const countTagGroupParentheses = function (hedString) {
268238
/**
269239
* Check if a comma is missing after an opening parenthesis.
270240
*/
271-
const isCommaMissingAfterClosingParenthesis = function (
272-
lastNonEmptyCharacter,
273-
currentCharacter,
274-
) {
241+
const isCommaMissingAfterClosingParenthesis = function (lastNonEmptyCharacter, currentCharacter) {
275242
return (
276243
lastNonEmptyCharacter === closingGroupCharacter &&
277-
!(
278-
delimiters.has(currentCharacter) ||
279-
currentCharacter === closingGroupCharacter
280-
)
244+
!(delimiters.has(currentCharacter) || currentCharacter === closingGroupCharacter)
281245
)
282246
}
283247

@@ -314,12 +278,7 @@ const findDelimiterIssuesInHedString = function (hedString) {
314278
} else {
315279
issues.push(generateIssue('invalidTag', { tag: currentTag }))
316280
}
317-
} else if (
318-
isCommaMissingAfterClosingParenthesis(
319-
lastNonEmptyValidCharacter,
320-
currentCharacter,
321-
)
322-
) {
281+
} else if (isCommaMissingAfterClosingParenthesis(lastNonEmptyValidCharacter, currentCharacter)) {
323282
issues.push(
324283
generateIssue('commaMissing', {
325284
tag: currentTag.slice(0, -1),
@@ -346,7 +305,7 @@ const findDelimiterIssuesInHedString = function (hedString) {
346305
* Validate the full unparsed HED string.
347306
*
348307
* @param {string} hedString The unparsed HED string.
349-
* @return {object<string, Issue[]>} String substitution issues and other issues.
308+
* @return {Object<string, Issue[]>} String substitution issues and other issues.
350309
*/
351310
const validateFullUnparsedHedString = function (hedString) {
352311
const [fixedHedString, substitutionIssues] = substituteCharacters(hedString)
@@ -364,38 +323,27 @@ const validateFullUnparsedHedString = function (hedString) {
364323
const mergeParsingIssues = function (previousIssues, currentIssues) {
365324
for (const key of Object.keys(currentIssues)) {
366325
previousIssues[key] =
367-
previousIssues[key] !== undefined
368-
? previousIssues[key].concat(currentIssues[key])
369-
: currentIssues[key]
326+
previousIssues[key] !== undefined ? previousIssues[key].concat(currentIssues[key]) : currentIssues[key]
370327
}
371328
}
372329

373330
/**
374-
* Parse a full HED string into a object of tag types.
331+
* Parse a full HED string into an object of tag types.
375332
*
376333
* @param {string} hedString The full HED string to parse.
377334
* @param {Schemas} hedSchemas The collection of HED schemas.
378-
* @returns {[ParsedHedString|null, object<string, Issue[]>]} The parsed HED tag data and an object containing lists of parsing issues.
335+
* @returns {[ParsedHedString|null, Object<string, Issue[]>]} The parsed HED tag data and an object containing lists of parsing issues.
379336
*/
380337
const parseHedString = function (hedString, hedSchemas) {
381338
const fullStringIssues = validateFullUnparsedHedString(hedString)
382339
if (fullStringIssues.delimiter.length > 0) {
383340
fullStringIssues.syntax = []
384341
return [null, fullStringIssues]
385342
}
386-
const parsedString = new ParsedHedString(hedString)
387343
const [hedTagList, splitIssues] = splitHedString(hedString, hedSchemas)
388-
parsedString.topLevelTags = findTopLevelTags(
389-
hedTagList,
390-
hedSchemas,
391-
parsedString,
392-
)
393-
const tagGroupIssues = findTagGroups(
394-
hedTagList,
395-
hedSchemas,
396-
parsedString,
397-
true,
398-
)
344+
const parsedString = new ParsedHedString(hedString)
345+
parsedString.topLevelTags = findTopLevelTags(hedTagList, hedSchemas, parsedString)
346+
const tagGroupIssues = findTagGroups(hedTagList, hedSchemas, parsedString, true)
399347
const parsingIssues = Object.assign(fullStringIssues, splitIssues)
400348
for (const tagGroup of tagGroupIssues) {
401349
mergeParsingIssues(parsingIssues, tagGroup)
@@ -408,7 +356,7 @@ const parseHedString = function (hedString, hedSchemas) {
408356
*
409357
* @param {string[]} hedStrings A set of HED strings.
410358
* @param {Schemas} hedSchemas The collection of HED schemas.
411-
* @return {[ParsedHedString[], object<string, Issue[]>]} The parsed HED strings and any issues found.
359+
* @return {[ParsedHedString[], Object<string, Issue[]>]} The parsed HED strings and any issues found.
412360
*/
413361
const parseHedStrings = function (hedStrings, hedSchemas) {
414362
return hedStrings

0 commit comments

Comments
 (0)