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

Complete implementation the deprecations API #2207

Merged
merged 11 commits into from
Apr 3, 2024
Merged

Complete implementation the deprecations API #2207

merged 11 commits into from
Apr 3, 2024

Conversation

jathak
Copy link
Member

@jathak jathak commented Apr 1, 2024

This implements the full deprecations API for the JS API and the embedded compiler, and also adds silenceDeprecations/--silence-deprecation to the Dart API and CLI to complete those implementations.

See sass/sass#3826
See sass/sass-spec#1967
[skip sass-embedded]

@jathak jathak requested a review from nex3 April 1, 2024 21:36
CHANGELOG.md Outdated
Comment on lines 5 to 9
* The deprecations API is now available in the JS API! The `compile` methods
support the same `fatalDeprecations` and `futureDeprecations` options that
were already available in the Dart API and the CLI, as well as a new
`silenceDeprecations` option that allows you to silence deprecation warnings
of a given type.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a fair bet that most JS API users don't know or follow the Dart API, so it's probably better to frame this as adding three new features to the JS API rather than bringing two from the Dart API and adding one new

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

CHANGELOG.md Outdated

### Command-Line Interface

* Add a new `--silence-deprecation` flag to match the new JS API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, although to a lesser extent, the CLI users are a somewhat different set than the JS API users. Better to keep the CLI descriptions as self-contained as possible—it's less net effort for us to duplicate some prose than for a bunch of readers to read extra paragraphs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

CHANGELOG.md Outdated
all deprecations, but will be used once some deprecations become obsolete in
Dart Sass 2.0.0.

* Fix a bug where `compileStringToResultAsync` ignored `fatalDeprecations` and
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd mark this as **Potentially breaking bug fix:** on the off chance that someone was doing it without realizing that it wasn't failing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

for (var deprecation in Deprecation.values)
if (deprecation.deprecatedIn != null &&
deprecation.description != null)
deprecation.id: deprecation.description!,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use if ... case to avoid this nullability assertion

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

lib/src/js/compile.dart Show resolved Hide resolved
}
}
for (var deprecation in silenceDeprecations) {
if (deprecation == Deprecation.userAuthored) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this block a switch statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Trace? trace,
bool deprecation = false,
Deprecation? deprecationType}) {
if (deprecation && deprecationType != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A benefit of the old pattern of having a separate warnForDeprecation() method is that it's clear from the static types that every deprecation warning has to have a deprecationType attached to it. Unless there's a technical reason to fold that into warn(), I think I'd prefer to keep it the old way. (If they do need to be merged, we should have error handling for what happens if deprecation and deprecationType disagree.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Now that there are other loggers that need to receive the deprecation type, using the same name for their method as the extension method meant that those other loggers could receive future deprecation warnings that hadn't been explicitly passed through by DeprecationProcessingLogger, so I wanted to separate those names.

I've now updated the method that LoggerWithDeprecationTypes implement to be internalWarn, which omits the boolean parameter and only has the Deprecation? one. In Dart Sass 2.0.0, we can eliminate internalWarn and LoggerWithDeprecationType by just changing Logger.warn's signature.

@@ -16,12 +16,15 @@ const _maxRepetitions = 5;

/// A logger that wraps an inner logger to have special handling for
/// deprecation warnings.
final class DeprecationHandlingLogger implements Logger {
final class DeprecationHandlingLogger implements DeprecationLogger {
Copy link
Contributor

Choose a reason for hiding this comment

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

The distinction between DeprecationLogger and DeprecationHandlingLogger is now pretty confusing, since neither the names nor the documentations clearly say what makes them different from one another.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've renamed this to DeprecationProcessingLogger and fleshed out the documentation to make it clearer that this one processes deprecation warnings (sometimes ignoring them or treating them as errors) based on the various flags.

The other one is now LoggerWithDeprecationType, which is clunky, but we can eliminate it in Dart Sass 2.0.0, so I'm not too worried about it.

Iterable<String>? functions,
Iterable<String>? fatalDeprecations,
Iterable<String>? futureDeprecations,
Iterable<String>? silenceDeprecations,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: remove trailing comma for consistency with other arglists.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 51 to 53
if (fatalDeprecations != null) {
request.fatalDeprecation.addAll(fatalDeprecations);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

Suggested change
if (fatalDeprecations != null) {
request.fatalDeprecation.addAll(fatalDeprecations);
}
fatalDeprecations.andThen(request.fatalDeprecation.addAll);

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jathak jathak requested a review from nex3 April 3, 2024 02:08
});

jsClass.defineStaticMethod(
'parse', (String version) => Version.parse(version));
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a discrepancy with the spec here: the JS version API we've specified only supports <number>.<number>.<number> versions, but Version.parse() supports the full semver range, including build identifiers and prerelease versions. To match the spec, this should probably throw an error if anything beyond numbers are included.

Comment on lines 97 to 104
for (var deprecation in Deprecation.values)
if (deprecation
case Deprecation(
deprecatedIn: Version(),
obsoleteIn: null,
:var description?
))
deprecation.id: description,
Copy link
Contributor

Choose a reason for hiding this comment

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

Between this and --fatal-deprecation, nearly half the length of the --help output is taken up by deprecation descriptions. WDYT about just linking to the Sass site's CLI docs instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think that makes more sense. Is there a short version of https://sass-lang.com/documentation/cli/dart-sass so we can link to it with #fatal-deprecation, #silence-deprecation and #future-deprecation?

@jathak jathak merged commit d9220d9 into main Apr 3, 2024
29 checks passed
@jathak jathak deleted the deprecations branch April 3, 2024 21:15
Friendly-users added a commit to Friendly-users/dart-sass that referenced this pull request Jun 28, 2024
-----
It is inappropriate to include political and offensive content in public code repositories.

Public code repositories should be neutral spaces for collaboration and community, free from personal or political views that could alienate or discriminate against others. Political content, especially that which targets or disparages minority groups, can be harmful and divisive. It can make people feel unwelcome and unsafe, and it can create a hostile work environment.

Please refrain from adding such content to public code repositories.
---

sass#2000 sass#2001 sass#2002 sass#2003 sass#2004 sass#2005 sass#2006 sass#2007 sass#2008 sass#2009 sass#2010 sass#2011 sass#2012 sass#2013 sass#2014 sass#2015 sass#2016 sass#2017 sass#2018 sass#2019 sass#2020 sass#2021 sass#2022 sass#2023 sass#2024 sass#2025 sass#2026 sass#2027 sass#2028 sass#2029 sass#2030 sass#2031 sass#2032 sass#2033 sass#2034 sass#2035 sass#2036 sass#2037 sass#2038 sass#2039 sass#2040 sass#2041 sass#2042 sass#2043 sass#2044 sass#2045 sass#2046 sass#2047 sass#2048 sass#2049 sass#2050 sass#2051 sass#2052 sass#2053 sass#2054 sass#2055 sass#2056 sass#2057 sass#2058 sass#2059 sass#2060 sass#2061 sass#2062 sass#2063 sass#2064 sass#2065 sass#2066 sass#2067 sass#2068 sass#2069 sass#2070 sass#2071 sass#2072 sass#2073 sass#2074 sass#2075 sass#2076 sass#2077 sass#2078 sass#2079 sass#2080 sass#2081 sass#2082 sass#2083 sass#2084 sass#2085 sass#2086 sass#2087 sass#2088 sass#2089 sass#2090 sass#2091 sass#2092 sass#2093 sass#2094 sass#2095 sass#2096 sass#2097 sass#2098 sass#2099 sass#2100 sass#2101 sass#2102 sass#2103 sass#2104 sass#2105 sass#2106 sass#2107 sass#2108 sass#2109 sass#2110 sass#2111 sass#2112 sass#2113 sass#2114 sass#2115 sass#2116 sass#2117 sass#2118 sass#2119 sass#2120 sass#2121 sass#2122 sass#2123 sass#2124 sass#2125 sass#2126 sass#2127 sass#2128 sass#2129 sass#2130 sass#2131 sass#2132 sass#2133 sass#2134 sass#2135 sass#2136 sass#2137 sass#2138 sass#2139 #2140 sass#2141 sass#2142 sass#2143 sass#2144 sass#2145 sass#2146 sass#2147 sass#2148 sass#2149 sass#2150 sass#2151 sass#2152 sass#2153 sass#2154 sass#2155 sass#2156 sass#2157 sass#2158 sass#2159 sass#2160 sass#2161 sass#2162 sass#2163 sass#2164 sass#2165 sass#2166 sass#2167 sass#2168 sass#2169 sass#2170 sass#2171 sass#2172 sass#2173 sass#2174 sass#2175 sass#2176 sass#2177 sass#2178 sass#2179 sass#2180 sass#2181 sass#2182 sass#2183 sass#2184 sass#2185 sass#2186 sass#2187 sass#2188 sass#2189 sass#2190 sass#2191 sass#2192 sass#2193 sass#2194 sass#2195 sass#2196 sass#2197 sass#2198 sass#2199 sass#2200 sass#2201 sass#2202 sass#2203 sass#2204 sass#2205 sass#2206 sass#2207 sass#2208 sass#2209 sass#2210 sass#2211 sass#2212 sass#2213 sass#2214 sass#2215 #2216 sass#2217 sass#2218 sass#2219 sass#2220 sass#2221 sass#2222 sass#2223 sass#2224 sass#2225 sass#2226 sass#2227 sass#2228 sass#2229 sass#2230 sass#2231 sass#2232 sass#2233 sass#2234 sass#2235 sass#2236 sass#2237 sass#2238 sass#2239 sass#2240 sass#2241 sass#2242 sass#2243 sass#2244 sass#2245 sass#2246 sass#2247 sass#2248 sass#2249 sass#2250 sass#2251 sass#2252 sass#2253 sass#2254 sass#2255 sass#2256 sass#2257 sass#2258 sass#2259 sass#2260 sass#2261 sass#2262 sass#2263 sass#2264 sass#2265 sass#2266 sass#2267 sass#2268 sass#2269 sass#2270
Friendly-users added a commit to Friendly-users/dart-sass that referenced this pull request Jul 2, 2024
-----
It is inappropriate to include political and offensive content in public code repositories.

Public code repositories should be neutral spaces for collaboration and community, free from personal or political views that could alienate or discriminate against others. Political content, especially that which targets or disparages minority groups, can be harmful and divisive. It can make people feel unwelcome and unsafe, and it can create a hostile work environment.

Please refrain from adding such content to public code repositories.
---

sass#2000 sass#2001 sass#2002 sass#2003 sass#2004 sass#2005 sass#2006 sass#2007 sass#2008 sass#2009 sass#2010 sass#2011 sass#2012 sass#2013 sass#2014 sass#2015 sass#2016 sass#2017 sass#2018 sass#2019 sass#2020 sass#2021 sass#2022 sass#2023 sass#2024 sass#2025 sass#2026 sass#2027 sass#2028 sass#2029 sass#2030 sass#2031 sass#2032 sass#2033 sass#2034 sass#2035 sass#2036 sass#2037 sass#2038 sass#2039 sass#2040 sass#2041 sass#2042 sass#2043 sass#2044 sass#2045 sass#2046 sass#2047 sass#2048 sass#2049 sass#2050 sass#2051 sass#2052 sass#2053 sass#2054 sass#2055 sass#2056 sass#2057 sass#2058 sass#2059 sass#2060 sass#2061 sass#2062 sass#2063 sass#2064 sass#2065 sass#2066 sass#2067 sass#2068 sass#2069 sass#2070 sass#2071 sass#2072 sass#2073 sass#2074 sass#2075 sass#2076 sass#2077 sass#2078 sass#2079 sass#2080 sass#2081 sass#2082 sass#2083 sass#2084 sass#2085 sass#2086 sass#2087 sass#2088 sass#2089 sass#2090 sass#2091 sass#2092 sass#2093 sass#2094 sass#2095 sass#2096 sass#2097 sass#2098 sass#2099 sass#2100 sass#2101 sass#2102 sass#2103 sass#2104 sass#2105 sass#2106 sass#2107 sass#2108 sass#2109 sass#2110 sass#2111 sass#2112 sass#2113 sass#2114 sass#2115 sass#2116 sass#2117 sass#2118 sass#2119 sass#2120 sass#2121 sass#2122 sass#2123 sass#2124 sass#2125 sass#2126 sass#2127 sass#2128 sass#2129 sass#2130 sass#2131 sass#2132 sass#2133 sass#2134 sass#2135 sass#2136 sass#2137 sass#2138 sass#2139 #2140 sass#2141 sass#2142 sass#2143 sass#2144 sass#2145 sass#2146 sass#2147 sass#2148 sass#2149 sass#2150 sass#2151 sass#2152 sass#2153 sass#2154 sass#2155 sass#2156 sass#2157 sass#2158 sass#2159 sass#2160 sass#2161 sass#2162 sass#2163 sass#2164 sass#2165 sass#2166 sass#2167 sass#2168 sass#2169 sass#2170 sass#2171 sass#2172 sass#2173 sass#2174 sass#2175 sass#2176 sass#2177 sass#2178 sass#2179 sass#2180 sass#2181 sass#2182 sass#2183 sass#2184 sass#2185 sass#2186 sass#2187 sass#2188 sass#2189 sass#2190 sass#2191 sass#2192 sass#2193 sass#2194 sass#2195 sass#2196 sass#2197 sass#2198 sass#2199 sass#2200 sass#2201 sass#2202 sass#2203 sass#2204 sass#2205 sass#2206 sass#2207 sass#2208 sass#2209 sass#2210 sass#2211 sass#2212 sass#2213 sass#2214 sass#2215 #2216 sass#2217 sass#2218 sass#2219 sass#2220 sass#2221 sass#2222 sass#2223 sass#2224 sass#2225 sass#2226 sass#2227 sass#2228 sass#2229 sass#2230 sass#2231 sass#2232 sass#2233 sass#2234 sass#2235 sass#2236 sass#2237 sass#2238 sass#2239 sass#2240 sass#2241 sass#2242 sass#2243 sass#2244 sass#2245 sass#2246 sass#2247 sass#2248 sass#2249 sass#2250 sass#2251 sass#2252 sass#2253 sass#2254 sass#2255 sass#2256 sass#2257 sass#2258 sass#2259 sass#2260 sass#2261 sass#2262 sass#2263 sass#2264 sass#2265 sass#2266 sass#2267 sass#2268 sass#2269 sass#2270 sass#2271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants