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

Ensure unsupported arguments to <Input> and <LinkTo> issue warnings or errors appropriately #77

Merged

Conversation

simonihmig
Copy link
Contributor

Fixes the remaining issue in #66.

Copy link
Contributor Author

@simonihmig simonihmig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue I am afraid I need a bit of guidance here, see my comments below...

const supportsAttribute = require('./supports-attribute');

module.exports = function checkAttributes(node, supported) {
let sourceReference = calculateLocationDisplay(null, node.loc.start);
Copy link
Contributor Author

@simonihmig simonihmig Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing null here as the moduleName, because I didn't find a way to access the template file name from within the AST transform. Any idea how this could work?

I am trying to give a useful hint to where the actual violation is located. Throwing an error will at least show the offending file downstream, but not for the warning obviously...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue any idea about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done now as suggested.

lib/helpers/check-attributes.js Show resolved Hide resolved
lib/ast-input-transform.js Outdated Show resolved Hide resolved
lib/helpers/check-attributes.js Show resolved Hide resolved
lib/helpers/check-attributes.js Outdated Show resolved Hide resolved
assert.dom('input').exists();
});

test('it ignores unknown attributes', async function(assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem quite correct, the assertion doesn't check to confirm that data-test-foo or aria-labelledby are missing on the input.

Also, once you update the tests to do those assertions you'll need to guard the test for <= 3.11 (because as of 3.11 this does work due to built-in support).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about this. And agree the test is not that useful. Ideally it would assert that we see a warning, but as that happens at build-time, I don't see an easy way to test that.

I was mainly writing that test to ensure that passing unsupported attributes at least does not blow up, and to see the warning when running it locally on my machine.

Adding an assertion that the attribute is missing feels awkward to me tbh, as ideally we would support arbitrary attributes, just as native angle brackets do (if we had a good way to polyfill that). So seeing tests as a way to formally describe the features of our piece of software, in this case we would not describe and test for a feature, but a missing feature, right? Which seems odd. Or in other words, should we find a way to polyfill support for arbitrary attributes, that added feature should not break any tests!

Just my 2¢ though...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mainly writing that test to ensure that passing unsupported attributes at least does not blow up, and to see the warning when running it locally on my machine.

Ya, this makes sense.

So seeing tests as a way to formally describe the features of our piece of software, in this case we would not describe and test for a feature, but a missing feature, right? Which seems odd.

Totally agree.

@rwjblue rwjblue changed the title WIP: Add checks for unsupported arguments Add validation to ensure unsupported arguments issue warnings or errors appropriately Aug 1, 2019
@rwjblue rwjblue merged commit e47cc8e into ember-polyfills:master Aug 1, 2019
@rwjblue rwjblue added the bug Something isn't working label Aug 1, 2019
@rwjblue rwjblue changed the title Add validation to ensure unsupported arguments issue warnings or errors appropriately Ensure unsupported arguments to <Input> and <LinkTo> issue warnings or errors appropriately Aug 1, 2019
@rwjblue rwjblue added bug Something isn't working and removed bug Something isn't working labels Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants