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

Bump eslint-config-marudor from 7.3.2 to 7.3.3 #22

Merged
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
3 changes: 2 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"cflags": ["-Wall"],
"xcode_settings": {"OTHER_CFLAGS": ["-Wall"]},
"win_delay_load_hook": "true",
"defines": ["LIBXML_XINCLUDE_ENABLED", "BUILDING_NODE_EXTENSION"],
"defines": ["LIBXML_XINCLUDE_ENABLED", "LIBXML_SCHEMATRON_ENABLED", "BUILDING_NODE_EXTENSION"],
"sources": [
"src/libxmljs.cc",
"src/xml_attribute.cc",
Expand Down Expand Up @@ -40,6 +40,7 @@
"vendor/libxml/parserInternals.c",
"vendor/libxml/pattern.c",
"vendor/libxml/relaxng.c",
"vendor/libxml/schematron.c",
"vendor/libxml/SAX2.c",
"vendor/libxml/SAX.c",
"vendor/libxml/tree.c",
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class Document {
toString(formatted?: boolean): string;
type(): 'document';
validate(xsdDoc: Document): boolean;
schematronValidate(schemaDoc: Document): boolean;
version(): string;
setDtd(name: string, ext: string, sys: string): void;
getDtd(): {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"node-pre-gyp": "^0.17.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.7.0",
"eslint-config-marudor": "^7.3.1",
Expand All @@ -53,6 +55,7 @@
"jest": "^26.4.2",
"jest-watch-typeahead": "^0.6.0",
"prettier": "^2.1.1",
"tsd": "^0.14.0"
"tsd": "^0.14.0",
"typescript": "^4.1.3"
}
}
58 changes: 58 additions & 0 deletions src/xml_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/relaxng.h>
#include <libxml/schematron.h>
#include <libxml/xinclude.h>
#include <libxml/xmlsave.h>
#include <libxml/xmlschemas.h>
Expand Down Expand Up @@ -674,6 +675,62 @@ NAN_METHOD(XmlDocument::RngValidate) {
return info.GetReturnValue().Set(Nan::New<Boolean>(valid));
}

NAN_METHOD(XmlDocument::SchematronValidate) {
if (info.Length() == 0 || info[0]->IsNullOrUndefined()) {
Nan::ThrowError("Must pass schema");
return;
}

if (!XmlDocument::constructor_template.Get(Isolate::GetCurrent())
->HasInstance(info[0])) {
Nan::ThrowError("Must pass XmlDocument");
return;
}

Nan::HandleScope scope;

Local<Array> errors = Nan::New<Array>();
xmlResetLastError();

XmlDocument *document = Nan::ObjectWrap::Unwrap<XmlDocument>(info.Holder());
XmlDocument *documentSchema = Nan::ObjectWrap::Unwrap<XmlDocument>(
Nan::To<Object>(info[0]).ToLocalChecked());

xmlSchematronParserCtxtPtr parser_ctxt =
xmlSchematronNewDocParserCtxt(documentSchema->xml_obj);
if (parser_ctxt == NULL) {
return Nan::ThrowError(
"Could not create context for Schematron schema parser");
}

xmlSchematronPtr schema = xmlSchematronParse(parser_ctxt);
if (schema == NULL) {
return Nan::ThrowError("Invalid Schematron schema");
}

xmlSchematronValidCtxtPtr valid_ctxt = xmlSchematronNewValidCtxt(schema, XML_SCHEMATRON_OUT_ERROR);
if (valid_ctxt == NULL) {
return Nan::ThrowError(
"Unable to create a validation context for the Schematron schema");
}
xmlSchematronSetValidStructuredErrors(valid_ctxt,
XmlSyntaxError::PushToArray,
reinterpret_cast<void *>(&errors));

bool valid = xmlSchematronValidateDoc(valid_ctxt, document->xml_obj) == 0;

xmlSchematronSetValidStructuredErrors(valid_ctxt, NULL, NULL);
Nan::Set(info.Holder(), Nan::New<String>("validationErrors").ToLocalChecked(),
errors)
.Check();

xmlSchematronFreeValidCtxt(valid_ctxt);
xmlSchematronFree(schema);
xmlSchematronFreeParserCtxt(parser_ctxt);

return info.GetReturnValue().Set(Nan::New<Boolean>(valid));
}

/// this is a blank object with prototype methods
/// not exposed to the user and not called from js
NAN_METHOD(XmlDocument::New) {
Expand Down Expand Up @@ -724,6 +781,7 @@ void XmlDocument::Initialize(Local<Object> target) {

Nan::SetPrototypeMethod(tmpl, "validate", XmlDocument::Validate);
Nan::SetPrototypeMethod(tmpl, "rngValidate", XmlDocument::RngValidate);
Nan::SetPrototypeMethod(tmpl, "schematronValidate", XmlDocument::SchematronValidate);
Nan::SetPrototypeMethod(tmpl, "_setDtd", XmlDocument::SetDtd);
Nan::SetPrototypeMethod(tmpl, "getDtd", XmlDocument::GetDtd);
Nan::SetPrototypeMethod(tmpl, "type", XmlDocument::type);
Expand Down
1 change: 1 addition & 0 deletions src/xml_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class XmlDocument : public Nan::ObjectWrap {
static NAN_METHOD(ToString);
static NAN_METHOD(Validate);
static NAN_METHOD(RngValidate);
static NAN_METHOD(SchematronValidate);
static NAN_METHOD(type);

// Static member variables
Expand Down
55 changes: 55 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,61 @@ describe('document', () => {
expect(xmlDocInvalid.validationErrors.length).toBe(1);
});

it('schematronValidate', () => {
const sch =
'<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">' +
'<pattern id="errors">' +
'<rule context="//addr">' +
'<assert test="state[last()=1] or @nullFlavor">All //addr elements MUST have element state.</assert>' +
'<assert test="streetAddressLine or @nullFlavor">All //addr elements MUST have element streetAddressLine</assert>' +
'</rule>' +
'</pattern>' +
'</schema>';

const xml_valid =
'<ClinicalDocument>' +
'<recordTarget>' +
'<patientRole>' +
'<addr use="H">' +
'<state>24</state>' +
'<streetAddressLine>example street</streetAddressLine>' +
'</addr>' +
'</patientRole>' +
'</recordTarget>' +
'</ClinicalDocument>';

const xml_invalid =
'<ClinicalDocument>' +
'<recordTarget>' +
'<patientRole>' +
'<addr use="H">' +
'<state>24</state>' +
'</addr>' +
'</patientRole>' +
'</recordTarget>' +
'</ClinicalDocument>';

const schDoc = libxml.parseXml(sch);
const xmlDocValid = libxml.parseXml(xml_valid);
const xmlDocInvalid = libxml.parseXml(xml_invalid);

expect(() => xmlDocValid.schematronValidate()).toThrow('Must pass schema');
expect(() => xmlDocValid.schematronValidate(undefined)).toThrow(
'Must pass schema'
);
expect(() => xmlDocValid.schematronValidate(null)).toThrow(
'Must pass schema'
);
expect(() => xmlDocValid.schematronValidate(0)).toThrow(
'Must pass XmlDocument'
);
expect(xmlDocValid.schematronValidate(schDoc)).toBe(true);
expect(xmlDocValid.validationErrors.length).toBe(0);

expect(xmlDocInvalid.schematronValidate(schDoc)).toBe(false);
expect(xmlDocInvalid.validationErrors.length).toBe(1);
});

it('validate memory usage', () => {
const xsd =
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="comment" type="xs:string"/></xs:schema>';
Expand Down
83 changes: 79 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,31 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.10.0.tgz#19ed3baf4bc4232c5a7fcd32eaca75c3a5baf9f3"
integrity sha512-h6/V46o6aXpKRlarP1AiJEXuCJ7cMQdlpfMDrcllIgX3dFkLwEBTXAoNP98ZoOmqd1xvymMVRAI4e7yVvlzWEg==
dependencies:
"@typescript-eslint/experimental-utils" "4.10.0"
"@typescript-eslint/scope-manager" "4.10.0"
debug "^4.1.1"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected]":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.10.0.tgz#dbf5d0f89802d5feaf7d11e5b32df29bbc2f3a0e"
integrity sha512-opX+7ai1sdWBOIoBgpVJrH5e89ra1KoLrJTz0UtWAa4IekkKmqDosk5r6xqRaNJfCXEfteW4HXQAwMdx+jjEmw==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/scope-manager" "4.10.0"
"@typescript-eslint/types" "4.10.0"
"@typescript-eslint/typescript-estree" "4.10.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/experimental-utils@^3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.10.1.tgz#e179ffc81a80ebcae2ea04e0332f8b251345a686"
Expand All @@ -669,6 +694,24 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.10.0.tgz#1a622b0847b765b2d8f0ede6f0cdd85f03d76031"
integrity sha512-amBvUUGBMadzCW6c/qaZmfr3t9PyevcSWw7hY2FuevdZVp5QPw/K76VSQ5Sw3BxlgYCHZcK6DjIhSZK0PQNsQg==
dependencies:
"@typescript-eslint/scope-manager" "4.10.0"
"@typescript-eslint/types" "4.10.0"
"@typescript-eslint/typescript-estree" "4.10.0"
debug "^4.1.1"

"@typescript-eslint/[email protected]":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.10.0.tgz#dbd7e1fc63d7363e3aaff742a6f2b8afdbac9d27"
integrity sha512-WAPVw35P+fcnOa8DEic0tQUhoJJsgt+g6DEcz257G7vHFMwmag58EfowdVbiNcdfcV27EFR0tUBVXkDoIvfisQ==
dependencies:
"@typescript-eslint/types" "4.10.0"
"@typescript-eslint/visitor-keys" "4.10.0"

"@typescript-eslint/[email protected]":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.7.0.tgz#2115526085fb72723ccdc1eeae75dec7126220ed"
Expand All @@ -682,6 +725,11 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.10.1.tgz#1d7463fa7c32d8a23ab508a803ca2fe26e758727"
integrity sha512-+3+FCUJIahE9q0lDi1WleYzjCwJs5hIsbugIgnbB+dSCYUxl8L6PwmsyOPFZde2hc1DlTo/xnkOgiTLSyAbHiQ==

"@typescript-eslint/[email protected]":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.10.0.tgz#12f983750ebad867f0c806e705c1953cd6415789"
integrity sha512-+dt5w1+Lqyd7wIPMa4XhJxUuE8+YF+vxQ6zxHyhLGHJjHiunPf0wSV8LtQwkpmAsRi1lEOoOIR30FG5S2HS33g==

"@typescript-eslint/[email protected]":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.7.0.tgz#5e95ef5c740f43d942542b35811f87b62fccca69"
Expand All @@ -701,6 +749,20 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected]":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.10.0.tgz#1e62e45fd57866afd42daf5e9fb6bd4e8dbcfa75"
integrity sha512-mGK0YRp9TOk6ZqZ98F++bW6X5kMTzCRROJkGXH62d2azhghmq+1LNLylkGe6uGUOQzD452NOAEth5VAF6PDo5g==
dependencies:
"@typescript-eslint/types" "4.10.0"
"@typescript-eslint/visitor-keys" "4.10.0"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected]":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.7.0.tgz#539531167f05ba20eb0b6785567076679e29d393"
Expand All @@ -722,6 +784,14 @@
dependencies:
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/[email protected]":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.10.0.tgz#9478822329a9bc8ebcc80623d7f79a01da5ee451"
integrity sha512-hPyz5qmDMuZWFtHZkjcCpkAKHX8vdu1G3YsCLEd25ryZgnJfj6FQuJ5/O7R+dB1ueszilJmAFMtlU4CA6se3Jg==
dependencies:
"@typescript-eslint/types" "4.10.0"
eslint-visitor-keys "^2.0.0"

"@typescript-eslint/[email protected]":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.7.0.tgz#6783824f22acfc49e754970ed21b88ac03b80e6f"
Expand Down Expand Up @@ -1721,9 +1791,9 @@ escodegen@^1.14.1:
source-map "~0.6.1"

eslint-config-marudor@^7.3.1:
version "7.3.2"
resolved "https://registry.yarnpkg.com/eslint-config-marudor/-/eslint-config-marudor-7.3.2.tgz#79e9f8dd53f64c9d142322823b219f54b49e90f5"
integrity sha512-sIunNqf49F7L05kRSVLsMf91W8zikxA9sBAPrZSBkeiXMG1cJ7dUQ4jX9tNz8OKpEu1FGko6GshjkcMnxnnhGA==
version "7.3.3"
resolved "https://registry.yarnpkg.com/eslint-config-marudor/-/eslint-config-marudor-7.3.3.tgz#6cbe5d775b00d4b252f96ffc542447d47a65e9e5"
integrity sha512-vfFWhe/bJd2dLDr6SCikgcd7CHOdTjQtcjZ0e3yJciejLVSKKvV2LQZ9AmjiIt9rlUZZbnugfpWHb126d1IpQg==

eslint-config-prettier@^7.0.0:
version "7.1.0"
Expand Down Expand Up @@ -4402,7 +4472,7 @@ regexpp@^2.0.1:
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f"
integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==

regexpp@^3.1.0:
regexpp@^3.0.0, regexpp@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"
integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==
Expand Down Expand Up @@ -5279,6 +5349,11 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==

union-value@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"
Expand Down