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

Remove warnings check from parse_success? method #2010

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/ruby_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ The full API is documented below.
* `Prism.load(source, serialized)` - load the serialized syntax tree using the source as a reference into a syntax tree
* `Prism.parse_comments(source)` - parse the comments corresponding to the given source string and return them
* `Prism.parse_file_comments(source)` - parse the comments corresponding to the given source file and return them
* `Prism.parse_success?(source)` - parse the syntax tree corresponding to the given source string and return true if it was parsed without errors or warnings
* `Prism.parse_file_success?(filepath)` - parse the syntax tree corresponding to the given source file and return true if it was parsed without errors or warnings
* `Prism.parse_success?(source)` - parse the syntax tree corresponding to the given source string and return true if it was parsed without errors
* `Prism.parse_file_success?(filepath)` - parse the syntax tree corresponding to the given source file and return true if it was parsed without errors

## Nodes

Expand Down
13 changes: 6 additions & 7 deletions ext/prism/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,7 @@ parse_lex_file(int argc, VALUE *argv, VALUE self) {
}

/**
* Parse the given input and return true if it parses without errors or
* warnings.
* Parse the given input and return true if it parses without errors.
*/
static VALUE
parse_input_success_p(pm_string_t *input, const pm_options_t *options) {
Expand All @@ -810,7 +809,7 @@ parse_input_success_p(pm_string_t *input, const pm_options_t *options) {
pm_node_t *node = pm_parse(&parser);
pm_node_destroy(&parser, node);

VALUE result = parser.error_list.size == 0 && parser.warning_list.size == 0 ? Qtrue : Qfalse;
VALUE result = parser.error_list.size == 0 ? Qtrue : Qfalse;
pm_parser_free(&parser);

return result;
Expand All @@ -820,8 +819,8 @@ parse_input_success_p(pm_string_t *input, const pm_options_t *options) {
* call-seq:
* Prism::parse_success?(source, **options) -> Array
*
* Parse the given string and return true if it parses without errors or
* warnings. For supported options, see Prism::parse.
* Parse the given string and return true if it parses without errors. For
* supported options, see Prism::parse.
*/
static VALUE
parse_success_p(int argc, VALUE *argv, VALUE self) {
Expand All @@ -840,8 +839,8 @@ parse_success_p(int argc, VALUE *argv, VALUE self) {
* call-seq:
* Prism::parse_file_success?(filepath, **options) -> Array
*
* Parse the given file and return true if it parses without errors or warnings.
* For supported options, see Prism::parse.
* Parse the given file and return true if it parses without errors. For
* supported options, see Prism::parse.
*/
static VALUE
parse_file_success_p(int argc, VALUE *argv, VALUE self) {
Expand Down
4 changes: 2 additions & 2 deletions lib/prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def self.load(source, serialized)
# :call-seq:
# Prism::parse_failure?(source, **options) -> bool
#
# Returns true if the source is invalid Ruby code.
# Returns true if the source parses with errors.
def self.parse_failure?(source, **options)
!parse_success?(source, **options)
end

# :call-seq:
# Prism::parse_file_failure?(filepath, **options) -> bool
#
# Returns true if the file at filepath is invalid Ruby code.
# Returns true if the file at filepath parses with errors.
def self.parse_file_failure?(filepath, **options)
!parse_file_success?(filepath, **options)
end
Expand Down
3 changes: 0 additions & 3 deletions test/prism/ruby_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def test_ruby_api
def test_parse_success?
assert Prism.parse_success?("1")
refute Prism.parse_success?("<>")

assert Prism.parse_success?("m //", verbose: false)
refute Prism.parse_success?("m //", verbose: true)
end

def test_parse_file_success?
Expand Down