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
[fix] jsx-uses-vars
: ignore namespaces
#2985
[fix] jsx-uses-vars
: ignore namespaces
#2985
Conversation
JSX namespaces are transpiled into strings, not identifiers.
I'm a bit confused. If they're compiled into strings, how could React possibly accept them? |
React doesn't support JSX namespaces, but other JSX implementations do. For example see https://github.com/remcohaszing/xast-namespaces/blob/main/__fixtures__/inherit-named-namespace.tsx |
This is eslint-plugin-react, though. It's not for non-react use cases. Ignoring namespaces might still be the right choice here, since they're invalid in react, but I'm not 100% confident of that. |
I get that. Still, Some rules are relevant to Preact or JSX in general without extra work needed. 🙂
What's making you doubt? The playground link shows namespaces are transpiled to strings, not identifiers. Reporting namespaces is always a false positive. Perhaps it makes sense to add a new rule then: |
What’s the semantics of this code when not using react? eg, how does something else know what it should resolve to? |
This can be configured in For the linked example, this is configured here For any known configuration, namespaces are converted to strings. So as far as this rule goes, namespaced JSX should be ignored, regardless whether React or any other library is used. |
Right, but "converted to strings" doesn't answer the question - what semantics do they have in any jsx transformation? "HTML element" or "custom component reference" are what I'm familiar with; what would a namespaced string possibly do? |
TL;DR: They represent XML elements. xast (XML AST) is a way to represent XML in JavaScript. In the linked code, I use xastscript, a library which allows to use hyperscript / JSX to create xast nodes. A more practical example can be found here. I use xastscript in a test to create XML for SSO using SAML. I have a change locally to change the that code snippet to use JSX. This looks pretty much the same as the raw xml it represents, but with variables. const tree = (
<samlp:Response
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Destination="http://localhost:9999/api/apps/7/saml/1/acs"
ID="_5190f0683c9e4b77a4e0a8ffd4d4a4dd"
InResponseTo="id27748888-5253-48bf-8cf5-b65f793b7643"
IssueInstant="2020-11-20T10:26:11.008603+00:00"
Version="2.0"
>
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
http://localhost:8000/saml/metadata.xml
</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#_5190f0683c9e4b77a4e0a8ffd4d4a4dd">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>{digest}</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
GKQRfvJ0BR1geBqUttE6eXZCj9Ac+n1KPrN7R9odfrL8mXaU71aqW+rkNRCRV8NrY019bHDNDlWBpYDMLwsqcA==
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIICKzCCAdWgAwIBAgIJAM8DxRNtPj90MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTEwODEyMjA1MTIzWhcNMTIwODExMjA1MTIzWjBFMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANcNmgm4YlSUAr2xdWei5aRU/DbWtsQ47gjkv28Ekje3ob+6q0M+D5phwYDcv9ygYmuJ5wOi1cPprsWdFWmvSusCAwEAAaOBpzCBpDAdBgNVHQ4EFgQUzyBR9+vE8bygqvD6CZ/w6aQPikMwdQYDVR0jBG4wbIAUzyBR9+vE8bygqvD6CZ/w6aQPikOhSaRHMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGSCCQDPA8UTbT4/dDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EAIQuPLA/mlMJAMF680kL7reX5WgyRwAtRzJK6FgNjE7kRaLZQ79UKYVYa0VAyrRdoNEyVhG4tJFEiQJzaLWsl/A==
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<samlp:Status>
<samlp:StatusCode Value={statusCode} />
</samlp:Status>
<saml:Assertion
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_2d1e69f46b0b4e569928a2a0861ff2a4"
IssueInstant="2020-11-20T10:26:11.008603+00:00"
Version="2.0"
>
<saml:Issuer>http://localhost:8000/saml/metadata.xml</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#_2d1e69f46b0b4e569928a2a0861ff2a4">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature/" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>aeMoD3gP962UNfpc8Qxd0aAELMo=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
Y+4rrPo0doC1Tos1zsGZJr7IgNtkbf4kVKE/Au/+RNCSSLrDSOur5D5Ic5cYMhRRzidZh1xqcxaliRjgXZK4Lg==
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIICKzCCAdWgAwIBAgIJAM8DxRNtPj90MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTEwODEyMjA1MTIzWhcNMTIwODExMjA1MTIzWjBFMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANcNmgm4YlSUAr2xdWei5aRU/DbWtsQ47gjkv28Ekje3ob+6q0M+D5phwYDcv9ygYmuJ5wOi1cPprsWdFWmvSusCAwEAAaOBpzCBpDAdBgNVHQ4EFgQUzyBR9+vE8bygqvD6CZ/w6aQPikMwdQYDVR0jBG4wbIAUzyBR9+vE8bygqvD6CZ/w6aQPikOhSaRHMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGSCCQDPA8UTbT4/dDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EAIQuPLA/mlMJAMF680kL7reX5WgyRwAtRzJK6FgNjE7kRaLZQ79UKYVYa0VAyrRdoNEyVhG4tJFEiQJzaLWsl/A==
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
{subject && (
<saml:Subject>
{subject.nameId && (
<saml:NameID
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:email"
SPNameQualifier="http://localhost:9999/api/apps/7/saml/1/metadata.xml"
>
alex@example.com
</saml:NameID>
)}
{subject.loginId && (
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData
InResponseTo="id27748888-5253-48bf-8cf5-b65f793b7643"
NotOnOrAfter="2020-11-20T10:41:11.008603+00:00"
Recipient="http://localhost:9999/api/apps/7/saml/1/acs"
/>
</saml:SubjectConfirmation>
)}
</saml:Subject>
)}
<saml:Conditions
NotBefore="2020-11-20T10:23:11.008603+00:00"
NotOnOrAfter="2020-11-20T10:41:11.008603+00:00"
>
<saml:AudienceRestriction>
<saml:Audience>http://localhost:9999/api/apps/7/saml/1/metadata.xml</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2020-11-20T10:26:11.008603+00:00">
<saml:AuthnContext>
<saml:AuthnContextClassRef>
urn:oasis:names:tc:SAML:2.0:ac:classes:Password
</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="foo" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue>bar</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>
); |
ok, so there's no custom code being ran for those, it's just custom tag names? |
That's right |
9df5b41
to
f864ac1
Compare
JSX namespaces are transpiled into strings, not identifiers.
This can be seen in here for TypeScript.
Babel behaves the same, but it requires a configuration which isn’t supported by their playground.