eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Change `filter` front matter key to `filterOut` for v2.x

Open Zearin opened this issue 3 years ago • 9 comments
trafficstars

Is your feature request related to a problem? Please describe. When writing a .filter( … ) function in JavaScript, I tend to think of it as “Filter FOR «truthy condition»”. In other words, I think in terms of what I want to include.

But the filter front matter key filters based on what you want to exclude.

Describe the solution you'd like For more human-friendliness, I recommend changing the name of this key to filterOut for the official v2.x release of Eleventy.

Describe alternatives you've considered Optionally, you could allow Eleventy to continue support for filter with a deprecation warning.

(You could also keep the filter keyword, and flip the logic that Eleventy uses…but that is hostile to users that have become used to the current behavior.)

Zearin avatar Aug 08 '22 16:08 Zearin

Maybe we could use ‘exclude’ instead of ‘filterOut’ if that’s not already taken

mayankkamboj47 avatar Aug 13 '22 04:08 mayankkamboj47

I agree with @mayankkamboj47 to choose 'exclude' over 'filterOut'. Not only because it seems more semantic to me, but it also allows for the addition of an 'include' property which might filter what to include from the collection.

Snapstromegon avatar Aug 28 '22 11:08 Snapstromegon

@zachleat Please don’t forget this before v2.0 leaves beta! 🙏

Zearin avatar Jan 20 '23 16:01 Zearin

I'm all for adding include and exclude properties and deprecating filter.

uncenter avatar Nov 11 '23 21:11 uncenter

Especially @zachleat: I'm willing to create a PR for this, but how would you expect it to work when both include and exclude are specified?

I personally see these options:

1. Disallow Just throw/warn/whatever when both keys are specified

2. Exclude over Include Exclude items even when they are included.

3. Include over Exclude Include items even when they are excluded.

I'd personally tend to use option 1, but I'm completely open to suggestions.

Snapstromegon avatar Nov 12 '23 16:11 Snapstromegon

Option 1 is the only one that makes sense to me, I'd go with that.

uncenter avatar Nov 12 '23 17:11 uncenter

Maybe this can squeeze in before the final release of v3?

Zearin avatar Jan 13 '24 14:01 Zearin