Ruby: Recognise File.atomic_write as a file writer

This method is an ActiveSupport extension, but there's no harm in
recognising it universally as any identically-named method is likely to
also be a file writer.
This commit is contained in:
Harry Maclean
2022-06-16 13:46:16 +12:00
parent 0ce14fc4e5
commit a298f5eb5e
3 changed files with 9 additions and 1 deletions

View File

@@ -137,7 +137,7 @@ class IOOrFileWriteMethodCall extends IOOrFileMethodCall {
receiverKind = "class" and
api = ["IO", "File"] and
this = API::getTopLevelMember(api).getAMethodCall(methodName) and
methodName = ["binwrite", "write"] and
methodName = ["binwrite", "write", "atomic_write"] and
dataNode = this.getArgument(1)
or
// e.g. `{IO,File}.new("foo.txt", "a+).puts("hello")`

View File

@@ -76,6 +76,8 @@ fileSystemAccesses
| Files.rb:41:1:41:26 | call to open |
| Files.rb:41:1:41:43 | call to write |
| Files.rb:48:1:48:40 | call to printf |
| Files.rb:49:1:49:30 | call to write |
| Files.rb:50:1:50:37 | call to atomic_write |
fileNameSources
| Files.rb:10:6:10:18 | call to path |
| Files.rb:11:6:11:21 | call to to_path |
@@ -86,7 +88,11 @@ fileWriters
| Files.rb:40:1:40:22 | call to puts |
| Files.rb:41:1:41:43 | call to write |
| Files.rb:48:1:48:40 | call to printf |
| Files.rb:49:1:49:30 | call to write |
| Files.rb:50:1:50:37 | call to atomic_write |
fileSystemWriteAccesses
| Files.rb:40:1:40:22 | call to puts |
| Files.rb:41:1:41:43 | call to write |
| Files.rb:48:1:48:40 | call to printf |
| Files.rb:49:1:49:30 | call to write |
| Files.rb:50:1:50:37 | call to atomic_write |

View File

@@ -46,3 +46,5 @@ str_1 = "hello"
int_1 = 123
# File/IO write
io_file.printf("%s: %d\n", str_1, int_1)
File.write("foo.txt", "hello")
File.atomic_write("foo.txt", "hello")