Comments (4)
My 2 cents is I think this is somewhat unlikely to be changed, but maybe a "no assignment in call" rule would be a possibility for ameba.
EDIT: My reasoning is this would ofc be a breaking change so would have to wait for Crystal 2.0, and because I think having this is somewhat helpful. E.g. in my specs I frequently do like:
collection.add "foo", foo = ART::Route.new "/foo"
so that later on in the spec I can use foo
. Really only saves a line but keeps things cleaner imo 🤷.
from crystal.
This syntax is necessary for very basic things like the getter
macro:
class Foo
# this is how the macro call really looks like, even though
# most of the time `getter` is never used with parentheses
getter(x = 1)
end
Unfortunately this also means Ameba shouldn't detect this, as it takes a semantic pass to determine whether getter
is a macro or def cell, and Ameba is purely syntactic.
Instead, when there are multiple optional parameters, personally I'd make all of them named:
def foo(*, bar = true, baz = false)
end
foo(baz = true) # not allowed
foo(baz: true) # okay
foo(baz: baz = true) # okay
foo(bar: baz = true) # okay
from crystal.
This seems like a perfect feature for a linter. The linter needs access to the semantic stage, so ameba currently cannot implement that. But it could be a future expansion (if not for ameba, then as a separate tool). Semantic linting is certainly useful in general.
from crystal.
This syntax is necessary for very basic things like the getter macro
...
Crap, I didn't think of that. Is it possible to get that at the compiler level then?
Maybe at least a warning that is triggered when the local variable has the name of one of the function parameters, but doesn't match it position-wise:
def foo(bar = true, baz = false)
end
foo(bar = false) # no warning
foo(baz = true) # compiler warning
Instead, when there are multiple optional parameters, personally I'd make all of them named:
That's what we will use in the future, I guess.
from crystal.
Related Issues (20)
- Weird compilation error happening only on CI Github Action HOT 8
- Fail to compile in path with whitespace HOT 3
- Compiler error when output directory for object file is missing HOT 3
- It's impossible to create a regex that is MULTILINE but not DOT_ALL HOT 2
- Error: read before assignment to local variable '' HOT 2
- `Enumerable` method to find the first truthy block result and return that result HOT 8
- Macro Code Coverage
- `MacroIf` then/else missing location information HOT 1
- Doc error for Channel#close, Channel#close? when channel is buffered channel.
- Invalid memory access in release mode with LLVM 18 HOT 2
- `Number.new` causes `IndexError` with blank value and `whitespace: false`
- Ensuring `class_getter` runs exactly once under concurrent access HOT 3
- Methods with a return type of `self` automatically return `self` HOT 3
- Store annotations within the node they annotate HOT 3
- Method overloads and type specificity are influenced by order of definition HOT 5
- Error: undefined method 'to_unsafe' for Foo (compile-time type is MyModule) HOT 4
- Filters do not work with dependencies tool on Windows HOT 1
- Zstd - "you've found a bug in the Crystal compiler. Please open an issue .. " HOT 2
- `XML::Error.errors` leaks memory HOT 15
- Nil assertion failed (NilAssertionError) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal.