Skip to content

Commit

Permalink
Add naming convention rule for variables (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins authored Mar 4, 2023
1 parent 5ad4e5c commit 7ddcf92
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module.exports = {
],
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/naming-convention': ['error', {
selector: 'variable',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allowDouble',
trailingUnderscore: 'allowDouble',
}],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
Expand Down
3 changes: 2 additions & 1 deletion examples/vanilla-quill/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ async function main() {
to = from + op.retain;
}
console.log(
`%c local: ${from}-${to}: ${op.insert} ${op.attributes ? JSON.stringify(op.attributes) : '{}'
`%c local: ${from}-${to}: ${op.insert} ${
op.attributes ? JSON.stringify(op.attributes) : '{}'
}`,
'color: green',
);
Expand Down
4 changes: 1 addition & 3 deletions src/yorkie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export {

// TODO(hackerwins): ValueChange is missing in TextChange in the index.d.ts file
// if not exported. We need to find a way to handle this without exporting the below.
export {
ValueChange,
} from '@yorkie-js-sdk/src/document/crdt/rga_tree_split';
export { ValueChange } from '@yorkie-js-sdk/src/document/crdt/rga_tree_split';

export {
Primitive,
Expand Down
24 changes: 12 additions & 12 deletions test/integration/gc_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,27 @@ describe('Garbage Collection', function () {
const doc = new yorkie.Document<{ k1: Text }>('test-doc');
assert.equal('{}', doc.toSortedJSON());

let expected_msg = '{"k1":[{"val":"Hello "},{"val":"mario"}]}';
let expectedMessage = '{"k1":[{"val":"Hello "},{"val":"mario"}]}';
doc.update((root) => {
root.k1 = new Text();
root.k1.edit(0, 0, 'Hello world');
root.k1.edit(6, 11, 'mario');
assert.equal(expected_msg, root.toJSON!());
assert.equal(expectedMessage, root.toJSON!());
}, 'edit text k1');
assert.equal(expected_msg, doc.toSortedJSON());
assert.equal(expectedMessage, doc.toSortedJSON());
assert.equal(1, doc.getGarbageLen());

expected_msg =
expectedMessage =
'{"k1":[{"val":"Hi"},{"val":" "},{"val":"j"},{"val":"ane"}]}';

doc.update((root) => {
const text = root['k1'];
text.edit(0, 5, 'Hi');
text.edit(3, 4, 'j');
text.edit(4, 8, 'ane');
assert.equal(expected_msg, root.toJSON!());
assert.equal(expectedMessage, root.toJSON!());
}, 'deletes 2');
assert.equal(expected_msg, doc.toSortedJSON());
assert.equal(expectedMessage, doc.toSortedJSON());

const expectedGarbageLen = 4;
assert.equal(expectedGarbageLen, doc.getGarbageLen());
Expand All @@ -141,29 +141,29 @@ describe('Garbage Collection', function () {
const doc = new yorkie.Document<{ k1: Text }>('test-doc');
assert.equal('{}', doc.toSortedJSON());

let expected_msg =
let expectedMessage =
'{"k1":[{"attrs":{"b":"1"},"val":"Hello "},{"val":"mario"}]}';

doc.update((root) => {
root.k1 = new Text();
root.k1.edit(0, 0, 'Hello world', { b: '1' });
root.k1.edit(6, 11, 'mario');
assert.equal(expected_msg, root.toJSON!());
assert.equal(expectedMessage, root.toJSON!());
}, 'edit text k1');
assert.equal(expected_msg, doc.toSortedJSON());
assert.equal(expectedMessage, doc.toSortedJSON());
assert.equal(1, doc.getGarbageLen());

expected_msg =
expectedMessage =
'{"k1":[{"attrs":{"b":"1"},"val":"Hi"},{"attrs":{"b":"1"},"val":" "},{"val":"j"},{"attrs":{"b":"1"},"val":"ane"}]}';

doc.update((root) => {
const text = root['k1'];
text.edit(0, 5, 'Hi', { b: '1' });
text.edit(3, 4, 'j');
text.edit(4, 8, 'ane', { b: '1' });
assert.equal(expected_msg, root.toJSON!());
assert.equal(expectedMessage, root.toJSON!());
}, 'edit text k1');
assert.equal(expected_msg, doc.toSortedJSON());
assert.equal(expectedMessage, doc.toSortedJSON());

const expectedGarbageLen = 4;
assert.equal(expectedGarbageLen, doc.getGarbageLen());
Expand Down
6 changes: 3 additions & 3 deletions test/unit/api/converter_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ describe('Converter', function () {
});

it('convert hex string <-> byte array', function () {
const hex_str = '0123456789abcdef01234567';
const bytes = converter.toUint8Array(hex_str);
const hexString = '0123456789abcdef01234567';
const bytes = converter.toUint8Array(hexString);
assert.equal(bytes.length, 12);
assert.equal(converter.toHexString(bytes), hex_str);
assert.equal(converter.toHexString(bytes), hexString);
});
});
30 changes: 15 additions & 15 deletions test/unit/document/json/root_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ describe('ROOT', function () {
assert.equal(Object.keys(k2.toJS()).length, 0);

// set '$.k2.1'
const k2_1 = CRDTArray.create(cc.issueTimeTicket());
k2.set('1', k2_1);
root.registerElement(k2_1, k2);
const k2Dot1 = CRDTArray.create(cc.issueTimeTicket());
k2.set('1', k2Dot1);
root.registerElement(k2Dot1, k2);
assert.equal(root.getElementMapSize(), 3);
assert.equal(root.findByCreatedAt(k2_1.getCreatedAt()), k2_1);
assert.equal(root.createPath(k2_1.getCreatedAt()), '$.k2.1');
assert.equal(root.findByCreatedAt(k2Dot1.getCreatedAt()), k2Dot1);
assert.equal(root.createPath(k2Dot1.getCreatedAt()), '$.k2.1');

// set '$.k2.1.0'
const k2_1_0 = Primitive.of('0', cc.issueTimeTicket());
k2_1.insertAfter(k2_1.getLastCreatedAt(), k2_1_0);
root.registerElement(k2_1_0, k2_1);
const k2Dot1Dot0 = Primitive.of('0', cc.issueTimeTicket());
k2Dot1.insertAfter(k2Dot1.getLastCreatedAt(), k2Dot1Dot0);
root.registerElement(k2Dot1Dot0, k2Dot1);
assert.equal(root.getElementMapSize(), 4);
assert.equal(root.findByCreatedAt(k2_1_0.getCreatedAt()), k2_1_0);
assert.equal(root.createPath(k2_1_0.getCreatedAt()), '$.k2.1.0');
assert.equal(root.findByCreatedAt(k2Dot1Dot0.getCreatedAt()), k2Dot1Dot0);
assert.equal(root.createPath(k2Dot1Dot0.getCreatedAt()), '$.k2.1.0');

// set '$.k2.1.1'
const k2_1_1 = Primitive.of('1', cc.issueTimeTicket());
k2_1.insertAfter(k2_1_0.getCreatedAt(), k2_1_1);
root.registerElement(k2_1_1, k2_1);
const k2dot1dot1 = Primitive.of('1', cc.issueTimeTicket());
k2Dot1.insertAfter(k2Dot1Dot0.getCreatedAt(), k2dot1dot1);
root.registerElement(k2dot1dot1, k2Dot1);
assert.equal(root.getElementMapSize(), 5);
assert.equal(root.findByCreatedAt(k2_1_1.getCreatedAt()), k2_1_1);
assert.equal(root.createPath(k2_1_1.getCreatedAt()), '$.k2.1.1');
assert.equal(root.findByCreatedAt(k2dot1dot1.getCreatedAt()), k2dot1dot1);
assert.equal(root.createPath(k2dot1dot1.getCreatedAt()), '$.k2.1.1');
});

it('garbage collection test for array', function () {
Expand Down

0 comments on commit 7ddcf92

Please sign in to comment.