Update code_buffer

This commit is contained in:
thomashii 2021-05-18 21:47:54 +08:00
parent 03857aba7c
commit 94d3adb3f1
7 changed files with 20 additions and 13 deletions

View file

@ -1,3 +1,6 @@
# 2.0.3
* Resolved static analysis warnings
# 2.0.2
* Updated README
# 2.0.1

View file

@ -1,5 +1,5 @@
# angel3_code_buffer
[![version](https://img.shields.io/badge/pub-v2.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_code_buffer)
[![version](https://img.shields.io/badge/pub-v2.0.3-brightgreen)](https://pub.dartlang.org/packages/angel3_code_buffer)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)

View file

@ -1,3 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false

View file

@ -3,7 +3,7 @@ import 'package:test/test.dart';
/// Use a `CodeBuffer` just like any regular `StringBuffer`:
String someFunc() {
var buf = new CodeBuffer();
var buf = CodeBuffer();
buf
..write('hello ')
..writeln('world!');
@ -12,16 +12,16 @@ String someFunc() {
/// However, a `CodeBuffer` supports indentation.
void someOtherFunc() {
var buf = new CodeBuffer();
var buf = CodeBuffer();
// Custom options...
// ignore: unused_local_variable
var customBuf =
new CodeBuffer(newline: '\r\n', space: '\t', trailingNewline: true);
CodeBuffer(newline: '\r\n', space: '\t', trailingNewline: true);
// Without whitespace..
// ignore: unused_local_variable
var minifyingBuf = new CodeBuffer.noWhitespace();
var minifyingBuf = CodeBuffer.noWhitespace();
// Any following lines will have an incremented indentation level...
buf.indent();

View file

@ -69,7 +69,7 @@ class CodeBuffer implements StringBuffer {
/// Copies the contents of this [CodeBuffer] into another, preserving indentation and source mapping information.
void copyInto(CodeBuffer other) {
if (_lines.isEmpty) return;
int i = 0;
var i = 0;
for (var line in _lines) {
// To compute offset:
@ -175,25 +175,27 @@ class CodeBuffer implements StringBuffer {
}
@override
void writeln([Object? obj = ""]) {
void writeln([Object? obj = '']) {
if (obj != null && obj != '') write(obj);
_currentLine = null;
_length++;
}
@override
void writeAll(Iterable objects, [String separator = ""]) {
void writeAll(Iterable objects, [String separator = '']) {
write(objects.join(separator));
}
@override
String toString() {
var buf = StringBuffer();
int i = 0;
var i = 0;
for (var line in lines) {
if (i++ > 0) buf.write(newline);
for (int j = 0; j < line.indentationLevel; j++) buf.write(space);
for (var j = 0; j < line.indentationLevel; j++) {
buf.write(space);
}
buf.write(line._buf.toString());
}

View file

@ -1,5 +1,5 @@
name: angel3_code_buffer
version: 2.0.2
version: 2.0.3
description: An advanced StringBuffer geared toward generating code, and source maps.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/code_buffer
environment:
@ -8,4 +8,5 @@ dependencies:
charcode: ^1.2.0
source_span: ^1.8.1
dev_dependencies:
test: ^1.17.3
test: ^1.17.3
pedantic: ^1.11.0

View file

@ -2,7 +2,7 @@ import 'package:charcode/charcode.dart';
import 'package:test/test.dart';
import 'package:angel3_code_buffer/angel3_code_buffer.dart';
main() {
void main() {
var buf = CodeBuffer();
tearDown(buf.clear);