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

Tests: Added strict checks for Prism.languages.extend #2572

Merged

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Oct 2, 2020

This adds a check for the best practice for the token order in the redef object that I outlined here. Tests will now fail if best practices aren't followed.

I tried to make the error message as descriptive as possible:

  90) Testing language 'mongodb'
       – should pass test case 'string_url_and_ip_feature':
     Error: The tokens in the redef object that overwrite existing tokens of
the extended language should be in the order of the existing tokens. The tokens
'number', 'function' should be in the order 'function', 'number'.

Actual method call (nonconforming):

        Prism.languages.extend('clike', {
                'class-name': [ ... 2 element(s) ],
                'keyword': [ ... 2 element(s) ],
                'number': RegExp,
                'function': RegExp,
                'operator': RegExp,
        });

For more information see: https://prismjs.com/docs/Prism.languages.html#.extend

There is one exception to this check: if the redef object is the clone of another language, then the order of properties won't be checked. This is because we don't have control over the property order in this case.
One might argue that this just letting bugs slip through (I would argue that) but for now it's the easiest solution just to ignore them. They haven't caused any trouble yet.

@github-actions
Copy link

JS File Size Changes (gzipped)

A total of 16 files have changed, with a combined diff of -5 B (-0.0%).

file master pull size diff % diff
components/prism-arduino.min.js 2 KB 1.99 KB -3 B -0.2%
components/prism-birb.min.js 398 B 399 B +1 B +0.3%
components/prism-c.min.js 887 B 886 B -1 B -0.1%
components/prism-d.min.js 1.22 KB 1.22 KB +2 B +0.2%
components/prism-gml.min.js 3.73 KB 3.74 KB +1 B +0.0%
components/prism-go.min.js 496 B 500 B +4 B +0.8%
components/prism-javascript.min.js 1.3 KB 1.29 KB -1 B -0.1%
components/prism-jolie.min.js 765 B 768 B +3 B +0.4%
components/prism-objectivec.min.js 441 B 441 B 0 Bytes 0%
components/prism-opencl.min.js 4.15 KB 4.15 KB -5 B -0.1%
components/prism-qore.min.js 596 B 596 B 0 Bytes 0%
components/prism-scala.min.js 482 B 484 B +2 B +0.4%
components/prism-sparql.min.js 629 B 629 B 0 Bytes 0%
components/prism-sqf.min.js 11.03 KB 11.02 KB -15 B -0.1%
components/prism-vala.min.js 983 B 987 B +4 B +0.4%
components/prism-vbnet.min.js 935 B 938 B +3 B +0.3%

Generated by 🚫 dangerJS against a6a87a5

@RunDevelopment RunDevelopment merged commit 8828500 into PrismJS:master Dec 22, 2020
@RunDevelopment RunDevelopment deleted the strict-languages-extend-checks branch December 22, 2020 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants