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

Convert noticeList from arrays to objects #6

Merged
merged 2 commits into from
Sep 2, 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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,23 @@ However, the user is, of course, free to create their own alternative version of

Still unfinished (in rough priority order):

1. Standardise parameters according to best practice (i.e., dereferencing, etc.)
1. Document the API
1. Publish to NPM so that the functions may be easily used by other software -- this may involve some changes to the folder structure, etc. as we only want the core functions published in this way -- not the demo code
1. Checking of general markdown and naked links
1. Testing and fine-tuning of error messages (e.g., comparing with tX), especially suppression of false alarms
1. Improve documentation
1. Optimise various different file fetches and caches (incl. using zips) for the demos
1. Is our `RepoCheck` the same as `ResourceContainerCheck`? Or is the latter more specific?
1. Standardise parameters according to best practice (i.e., dereferencing, etc.)
1. Understand and standardise React stuff, e.g., e.g., withStyles, etc.
1. Understand and standardise React stuff in the demos, e.g., e.g., withStyles, etc.
1. Write unit tests (especially for the core functions) and get them passing
1. Check for and remove left-over (but unused) code from the source projects that the original code was copied from
1. Remove all debug code and console logging, and to consider possible speed and memory optimizations

Known bugs:

1. The line number in the USFM Grammar check doesn't account for blank lines, so the real line number may be larger.

## Functionality and Limitations

See component `README` for details.
Expand Down
2 changes: 1 addition & 1 deletion makeNoticeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
with open(os.path.join(root, name), 'rt') as sourceFile:
for line in sourceFile:
if 'addNotice' in line and 'function addNotice' not in line \
and 'console.assert' not in line and 'noticeEntry[0]' not in line:
and 'console.assert' not in line and 'noticeEntry.priority' not in line:
strippedLine = line.strip()
if strippedLine.endswith(');'): strippedLine = strippedLine[:-2]
if not strippedLine.startswith('//'):
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "content-validation",
"description": "Functions for Checking uW Content/Resources.",
"version": "0.7.4",
"version": "0.8.1",
"private": false,
"homepage": "https://unfoldingword.github.io/content-validation/",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/core/BCS-usfm-grammar-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export function checkUSFMGrammar(BBB, strictnessString, filename, givenText, giv
/*
This function is only used for the demonstration pages -- not for the core!

BBB is a three-character UPPERCASE USFM book code or 'OBS'.

filename parameter can be an empty string if we don't have one.

Returns a result object containing a successList and a noticeList
Expand Down Expand Up @@ -100,7 +102,7 @@ export function checkUSFMGrammar(BBB, strictnessString, filename, givenText, giv
console.assert(typeof extract === 'string', `cUSFMgr addNotice5to8: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location !== undefined, "cUSFMgr addNotice5to8: 'location' parameter should be defined");
console.assert(typeof location === 'string', `cUSFMgr addNotice5to8: 'location' parameter should be a string not a '${typeof location}': ${location}`);
cugResult.noticeList.push([priority, BBB, "", "", message, index, extract, location]);
cugResult.noticeList.push({priority, BBB,C:'',V:'', message, index,extract, location});
}


Expand Down
2 changes: 1 addition & 1 deletion src/core/BCS-usfm-grammar-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This function simply packages the [Bridgeconn USFM Grammar Check](https://www.np

Our packaged function returns a list of success messages and a list of (prioritised) notice components.

The notices can then be further processed into a list of errors and a list of warnings as desired.
These raw notice components can then be filtered and/or sorted as required by the calling program, and then divided into a list of errors and a list of warnings or whatever as desired.

```js
import checkUSFMGrammar from './BCS-usfm-grammar-check';
Expand Down
2 changes: 1 addition & 1 deletion src/core/basic-file-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function doBasicFileChecks(filename, fileText, optionalFileLocation, opti
console.assert(typeof extract === 'string', `dBTCs addNotice5: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location !== undefined, "dBTCs addNotice5: 'location' parameter should be defined");
console.assert(typeof location === 'string', `dBTCs addNotice5: 'location' parameter should be a string not a '${typeof location}': ${location}`);
result.noticeList.push([priority, message, index, extract, location]);
result.noticeList.push({priority, message, index,extract, location});
}


Expand Down
2 changes: 1 addition & 1 deletion src/core/basic-text-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function doBasicTextChecks(fieldName, fieldText, allowedLinks, optionalFi
console.assert(typeof extract === 'string', `dBTCs addNotice5: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location !== undefined, "dBTCs addNotice5: 'location' parameter should be defined");
console.assert(typeof location === 'string', `dBTCs addNotice5: 'location' parameter should be a string not a '${typeof location}': ${location}`);
result.noticeList.push([priority, message, index, extract, location]);
result.noticeList.push({priority, message, index,extract, location});
}


Expand Down
4 changes: 2 additions & 2 deletions src/core/link-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function startLiveLinksCheck(linksList, existingNoticeList, callbackFuncti
console.assert(typeof extract==='string', `sLLC addNotice5: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location!==undefined, "sLLC addNotice5: 'location' parameter should be defined");
console.assert(typeof location==='string', `sLLC addNotice5: 'location' parameter should be a string not a '${typeof location}': ${location}`);
result.noticeList.push([priority, message, index, extract, location]);
result.noticeList.push({priority, message, index,extract, location});
}

// Now try fetching each link in turn
Expand Down Expand Up @@ -79,7 +79,7 @@ function doBasicLinkChecks(fieldName, fieldText, linkOptions, optionalFieldLocat
console.assert(typeof extract==='string', `sLLC addNotice5: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location!==undefined, "sLLC addNotice5: 'location' parameter should be defined");
console.assert(typeof location==='string', `sLLC addNotice5: 'location' parameter should be a string not a '${typeof location}': ${location}`);
result.noticeList.push([priority, message, index, extract, location]);
result.noticeList.push({priority, message, index,extract, location});
}

// Create our more detailed location string by prepending the fieldName
Expand Down
13 changes: 7 additions & 6 deletions src/core/manifest-text-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function checkManifestText(textName, manifestText, givenLocation, optionalChecki
cmtResult.successList.push(successString);
}
function addNotice8(priority, BBB,C,V, message, index, extract, location) {
// BBB is a three-character UPPERCASE USFM book code or 'OBS'.
// console.log(`checkManifestText Notice: (priority=${priority}) ${message}${index > 0 ? ` (at character ${index}${1})` : ""}${extract ? ` ${extract}` : ""}${location}`);
console.assert(priority !== undefined, "cManT addNotice8: 'priority' parameter should be defined");
console.assert(typeof priority === 'number', `cManT addNotice8: 'priority' parameter should be a number not a '${typeof priority}': ${priority}`);
Expand All @@ -58,7 +59,7 @@ function checkManifestText(textName, manifestText, givenLocation, optionalChecki
console.assert(typeof extract === 'string', `cManT addNotice8: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location !== undefined, "cManT addNotice8: 'location' parameter should be defined");
console.assert(typeof location === 'string', `cManT addNotice8: 'location' parameter should be a string not a '${typeof location}': ${location}`);
cmtResult.noticeList.push([priority, BBB,C,V, message, index, extract, location]);
cmtResult.noticeList.push({priority, BBB,C,V, message, index,extract, location});
}


Expand All @@ -83,12 +84,12 @@ function checkManifestText(textName, manifestText, givenLocation, optionalChecki
/* // Process results line by line
// suppressing undesired errors
for (const noticeEntry of cYtResultObject.noticeList)
if (noticeEntry[0] !== 191 // "Unexpected XXX character after space"
&& noticeEntry[1] !== "Unexpected ' character after space"
&& noticeEntry[1] !== "Unexpected space after ' character"
&& noticeEntry[1] !== "Unexpected space after [ character"
if (noticeEntry.priority !== 191 // "Unexpected XXX character after space"
&& noticeEntry.message !== "Unexpected ' character after space"
&& noticeEntry.message !== "Unexpected space after ' character"
&& noticeEntry.message !== "Unexpected space after [ character"
)
addNotice8(noticeEntry[0], noticeEntry[1], noticeEntry[2], noticeEntry[3], noticeEntry[4], noticeEntry[5], noticeEntry[6], noticeEntry[7]);
addNotice8(noticeEntry.priority, noticeEntry.message, noticeEntry[2], noticeEntry[3], noticeEntry[4], noticeEntry[5], noticeEntry[6], noticeEntry[7]);
*/
return cYtResultObject.formData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/manifest-text-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This function checks the given manifest.yaml for typical formatting errors. See https://resource-container.readthedocs.io/en/latest/manifest.html for the manifest specification.

It returns a list of success messages and a list of notice components. (The first component is always a priority number in the range 0..999.)
It returns a list of success messages and a list of notice components. (There is always a priority number in the range 0..999 and the main message string, as well as other helpful details as relevant.)

The notices can then be further processed into a list of errors and a list of warnings as desired.
These raw notice components can then be filtered and/or sorted as required by the calling program, and then divided into a list of errors and a list of warnings or whatever as desired.

```js
import checkManifestText from './manifest-text-check';
Expand Down
10 changes: 5 additions & 5 deletions src/core/markdown-text-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function checkMarkdownText(textName, markdownText, givenLocation, optionalChecki
console.assert(typeof extract === 'string', `cMdT addNotice5: 'extract' parameter should be a string not a '${typeof extract}': ${extract}`);
console.assert(location !== undefined, "cMdT addNotice5: 'location' parameter should be defined");
console.assert(typeof location === 'string', `cMdT addNotice5: 'location' parameter should be a string not a '${typeof location}': ${location}`);
result.noticeList.push([priority, message, index, extract, location]);
result.noticeList.push({priority, message, index, extract, location});
}
// end of addNotice5 function

Expand All @@ -76,11 +76,11 @@ function checkMarkdownText(textName, markdownText, givenLocation, optionalChecki
// If we need to put everything through addNotice5, e.g., for debugging or filtering
// process results line by line
for (const noticeEntry of dbtcResultObject.noticeList) {
console.assert(noticeEntry.length === 5, `MD doOurBasicTextChecks notice length=${noticeEntry.length}`);
if (!noticeEntry[1].startsWith("Unexpected doubled * characters") // 577 Markdown allows this
&& !noticeEntry[1].startsWith("Unexpected * character after space") // 191
console.assert(Object.keys(noticeEntry).length === 5, `MD doOurBasicTextChecks notice length=${Object.keys(noticeEntry).length}`);
if (!noticeEntry.message.startsWith("Unexpected doubled * characters") // 577 Markdown allows this
&& !noticeEntry.message.startsWith("Unexpected * character after space") // 191
)
addNotice5(noticeEntry[0], noticeEntry[1], noticeEntry[2], noticeEntry[3], noticeEntry[4]);
addNotice5(noticeEntry.priority, noticeEntry.message, noticeEntry.index, noticeEntry.extract, noticeEntry.location);
}
}
// end of doOurBasicTextChecks function
Expand Down
4 changes: 2 additions & 2 deletions src/core/markdown-text-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This function checks the given markdown-formatted text for typical formatting errors.

It returns a list of success messages and a list of notice components. (The first component is always a priority number in the range 0..999.)
It returns a list of success messages and a list of notice components. (There is always a priority number in the range 0..999 and the main message string, as well as other helpful details as relevant.)

The notices can then be further processed into a list of errors and a list of warnings as desired.
These raw notice components can then be filtered and/or sorted as required by the calling program, and then divided into a list of errors and a list of warnings or whatever as desired.

```js
import Markdown from 'react-markdown'
Expand Down
Loading