X Tutup
The Wayback Machine - https://web.archive.org/web/20220405131517/https://github.com/nodejs/node-addon-api/pull/1160
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

Format all code #1160

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Format all code #1160

wants to merge 3 commits into from

Conversation

Copy link
Contributor

@KevinEady KevinEady commented Apr 1, 2022

Format all JavaScript via eslint and all C++ via clang-format.

Fixes: #1146

@KevinEady
Copy link
Contributor Author

@KevinEady KevinEady commented Apr 1, 2022

JavaScript code was formatted via:

./node_modules/.bin/eslint '**/*.js' --fix

Not all JavaScript was auto-fixable and provided this remaining output log:


/Users/kevineady/Documents/Projects/node-addon-api/benchmark/property_descriptor.js
  21:15  error  'x' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/index.js
  3:7  error  Identifier 'include_dir' is not in camel case  camelcase

/Users/kevineady/Documents/Projects/node-addon-api/test/addon_build/index.js
  26:11  error  'stderr' is assigned a value but never used  no-unused-vars
  26:19  error  'stdout' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/array_buffer.js
  61:23  error  'WebAssembly' is not defined  no-undef

/Users/kevineady/Documents/Projects/node-addon-api/test/async_context.js
   9:5   error  Identifier 'async_hooks' is not in camel case    camelcase
  12:9   error  Identifier 'async_hooks' is not in camel case    camelcase
  12:21  error  Expected '===' and instead saw '=='              eqeqeq
  13:7   error  Identifier 'async_hooks' is not in camel case    camelcase
  30:9   error  'hook' is never reassigned. Use 'const' instead  prefer-const

/Users/kevineady/Documents/Projects/node-addon-api/test/async_worker.js
    8:5   error  Identifier 'async_hooks' is not in camel case    camelcase
   11:9   error  Identifier 'async_hooks' is not in camel case    camelcase
   11:21  error  Expected '===' and instead saw '=='              eqeqeq
   12:7   error  Identifier 'async_hooks' is not in camel case    camelcase
   29:9   error  'hook' is never reassigned. Use 'const' instead  prefer-const
   89:33  error  Expected '===' and instead saw '=='              eqeqeq
   91:30  error  Expected '===' and instead saw '=='              eqeqeq
  134:35  error  Expected '===' and instead saw '=='              eqeqeq
  136:32  error  Expected '===' and instead saw '=='              eqeqeq

/Users/kevineady/Documents/Projects/node-addon-api/test/basic_types/number.js
  26:3  error  Nested block is redundant  no-lone-blocks
  38:3  error  Nested block is redundant  no-lone-blocks
  50:3  error  Nested block is redundant  no-lone-blocks
  62:3  error  Nested block is redundant  no-lone-blocks
  73:3  error  Nested block is redundant  no-lone-blocks
  83:3  error  Nested block is redundant  no-lone-blocks
  98:3  error  Nested block is redundant  no-lone-blocks

/Users/kevineady/Documents/Projects/node-addon-api/test/callbackscope.js
   7:5   error  Identifier 'async_hooks' is not in camel case  camelcase
  10:9   error  Identifier 'async_hooks' is not in camel case  camelcase
  10:21  error  Expected '===' and instead saw '=='            eqeqeq
  11:7   error  Identifier 'async_hooks' is not in camel case  camelcase

/Users/kevineady/Documents/Projects/node-addon-api/test/dataview/dataview_read_write.js
   9:12  error  eval can be harmful                         no-eval
  13:12  error  eval can be harmful                         no-eval
  17:5   error  eval can be harmful                         no-eval
  20:12  error  'isLittleEndian' is defined but never used  no-unused-vars
  27:12  error  eval can be harmful                         no-eval
  31:5   error  eval can be harmful                         no-eval

/Users/kevineady/Documents/Projects/node-addon-api/test/env_cleanup.js
   6:9   error  Identifier 'binding_path' is not in camel case  camelcase
   7:9   error  Identifier 'remove_hooks' is not in camel case  camelcase
  11:25  error  Identifier 'remove_hooks' is not in camel case  camelcase
  18:14  error  Identifier 'remove_hooks' is not in camel case  camelcase
  25:9   error  Identifier 'remove_hooks' is not in camel case  camelcase
  40:9   error  Identifier 'remove_hooks' is not in camel case  camelcase

/Users/kevineady/Documents/Projects/node-addon-api/test/error_terminating_environment.js
   9:9   error  Identifier 'binding_path' is not in camel case          camelcase
  10:9   error  Identifier 'index_for_test_case' is not in camel case   camelcase
  26:9   error  Identifier 'binding_path' is not in camel case          camelcase
  27:9   error  Identifier 'index_for_test_case' is not in camel case   camelcase
  42:9   error  Identifier 'binding_path' is not in camel case          camelcase
  43:9   error  Identifier 'index_for_test_case' is not in camel case   camelcase
  47:11  error  Identifier 'index_for_test_case' is not in camel case   camelcase
  75:29  error  Identifier 'process_should_abort' is not in camel case  camelcase
  76:9   error  Identifier 'number_of_test_cases' is not in camel case  camelcase
  78:23  error  Identifier 'number_of_test_cases' is not in camel case  camelcase
  79:11  error  Identifier 'child_process' is not in camel case         camelcase
  89:9   error  Identifier 'process_should_abort' is not in camel case  camelcase

/Users/kevineady/Documents/Projects/node-addon-api/test/external.js
  36:7  error  Unreachable code  no-unreachable

/Users/kevineady/Documents/Projects/node-addon-api/test/maybe/index.js
  5:7  error  'os' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/movable_callbacks.js
  15:13  error  'external' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/name.js
  39:38  error  Expected Symbol to have a description  symbol-description

/Users/kevineady/Documents/Projects/node-addon-api/test/object/delete_property.js
  30:30  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins

/Users/kevineady/Documents/Projects/node-addon-api/test/object/object.js
  104:3   error  Nested block is redundant              no-lone-blocks
  117:21  error  Expected Symbol to have a description  symbol-description
  123:21  error  Expected Symbol to have a description  symbol-description

/Users/kevineady/Documents/Projects/node-addon-api/test/object/object_deprecated.js
  11:12  error  'assertPropertyIs' is defined but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/object_reference.js
  21:11  error  Identifier 'compare_test' is not in camel case  camelcase
  36:21  error  The array literal notation [] is preferable     no-array-constructor
  49:21  error  The array literal notation [] is preferable     no-array-constructor
  64:21  error  The array literal notation [] is preferable     no-array-constructor

/Users/kevineady/Documents/Projects/node-addon-api/test/objectwrap.js
   18:5   error  Nested block is redundant                  no-lone-blocks
   31:19  error  'read' is assigned a value but never used  no-unused-vars
   50:5   error  Nested block is redundant                  no-lone-blocks
   65:5   error  Nested block is redundant                  no-lone-blocks
   80:5   error  Nested block is redundant                  no-lone-blocks
  114:26  error  Expected '===' and instead saw '=='        eqeqeq
  128:5   error  Nested block is redundant                  no-lone-blocks
  168:19  error  'read' is assigned a value but never used  no-unused-vars
  186:5   error  Nested block is redundant                  no-lone-blocks
  201:5   error  Nested block is redundant                  no-lone-blocks
  253:18  error  Do not use 'new' for side effects          no-new

/Users/kevineady/Documents/Projects/node-addon-api/test/objectwrap_removewrap.js
  24:9  error  Do not use 'new' for side effects  no-new
  35:3  error  Unreachable code                   no-unreachable

/Users/kevineady/Documents/Projects/node-addon-api/test/objectwrap_worker_thread.js
  3:31  error  'workerData' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/symbol.js
   3:7   error  'buildType' is assigned a value but never used  no-unused-vars
  62:10  error  Comparing to itself is potentially pointless    no-self-compare
  63:10  error  Comparing to itself is potentially pointless    no-self-compare

/Users/kevineady/Documents/Projects/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js
  5:39  error  Expected '!==' and instead saw '!='  eqeqeq

/Users/kevineady/Documents/Projects/node-addon-api/test/thunking_manual.js
   4:7  error  'assert' is assigned a value but never used  no-unused-vars
  13:3  error  'object' is assigned a value but never used  no-unused-vars

/Users/kevineady/Documents/Projects/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js
  5:39  error  Expected '!==' and instead saw '!='  eqeqeq

/Users/kevineady/Documents/Projects/node-addon-api/tools/check-napi.js
   7:7   error  Identifier 'child_process' is not in camel case  camelcase
  74:7   error  Expected an error object to be thrown            no-throw-literal
  80:11  error  Expected an error object to be thrown            no-throw-literal

/Users/kevineady/Documents/Projects/node-addon-api/tools/conversion.js
   18:13   error    Expected '!==' and instead saw '!='        eqeqeq
   18:35   error    Expected '!==' and instead saw '!='        eqeqeq
   19:3    warning  Unexpected var, use let or const instead   no-var
   32:3    warning  Unexpected var, use let or const instead   no-var
   32:7    error    'ConfigFileOperations' is already defined  no-redeclare
   39:87   error    Unnecessary escape character: \"           no-useless-escape
   39:105  error    Unnecessary escape character: \"           no-useless-escape
   41:277  error    Unnecessary escape character: \"           no-useless-escape
   41:282  error    Unnecessary escape character: \"           no-useless-escape
   47:33   error    Unnecessary escape character: \"           no-useless-escape
   47:39   error    Unnecessary escape character: \"           no-useless-escape
   47:101  error    Unnecessary escape character: \"           no-useless-escape
   47:105  error    Unnecessary escape character: \"           no-useless-escape
   89:15   error    Unnecessary escape character: \)           no-useless-escape
  102:20   error    Unnecessary escape character: \.           no-useless-escape
  182:27   error    Unnecessary escape character: \(           no-useless-escape
  226:36   error    Unnecessary escape character: \(           no-useless-escape

✖ 108 problems (106 errors, 2 warnings)

C++ code was formatted via:

find . -type f -iname '*.cc' -print0 -or -iname '*.h' -print0 | xargs -0 ./node_modules/clang-format/bin/darwin_x64/clang-format -i --verbose

... and produced this output:

Formatting ./benchmark/property_descriptor.cc
Formatting ./benchmark/function_args.cc
Formatting ./test/threadsafe_function/threadsafe_function_ctx.cc
Formatting ./test/threadsafe_function/threadsafe_function_ptr.cc
Formatting ./test/threadsafe_function/threadsafe_function_sum.cc
Formatting ./test/threadsafe_function/threadsafe_function_existing_tsfn.cc
Formatting ./test/threadsafe_function/threadsafe_function.cc
Formatting ./test/threadsafe_function/threadsafe_function_unref.cc
Formatting ./test/name.cc
Formatting ./test/binding.cc
Formatting ./test/external.cc
Formatting ./test/thunking_manual.cc
Formatting ./test/function.cc
Formatting ./test/async_worker.cc
Formatting ./test/async_progress_worker.cc
Formatting ./test/date.cc
Formatting ./test/objectwrap_constructor_exception.cc
Formatting ./test/dataview/dataview_read_write.cc
Formatting ./test/dataview/dataview.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function_unref.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function_sum.cc
Formatting ./test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc
Formatting ./test/objectwrap_function.cc
Formatting ./test/maybe/check.cc
Formatting ./test/reference.cc
Formatting ./test/objectwrap.cc
Formatting ./test/env_cleanup.cc
Formatting ./test/async_progress_queue_worker.cc
Formatting ./test/buffer.cc
Formatting ./test/basic_types/array.cc
Formatting ./test/basic_types/value.cc
Formatting ./test/basic_types/number.cc
Formatting ./test/basic_types/boolean.cc
Formatting ./test/typedarray.cc
Formatting ./test/common/test_helper.h
Formatting ./test/object_reference.cc
Formatting ./test/binding-swallowexcept.cc
Formatting ./test/object/object_freeze_seal.cc
Formatting ./test/object/subscript_operator.cc
Formatting ./test/object/get_property.cc
Formatting ./test/object/object_deprecated.cc
Formatting ./test/object/set_property.cc
Formatting ./test/object/delete_property.cc
Formatting ./test/object/has_own_property.cc
Formatting ./test/object/has_property.cc
Formatting ./test/object/finalizer.cc
Formatting ./test/object/object.cc
Formatting ./test/movable_callbacks.cc
Formatting ./test/async_context.cc
Formatting ./test/bigint.cc
Formatting ./test/objectwrap_removewrap.cc
Formatting ./test/version_management.cc
Formatting ./test/objectwrap_multiple_inheritance.cc
Formatting ./test/symbol.cc
Formatting ./test/array_buffer.cc
Formatting ./test/promise.cc
Formatting ./test/memory_management.cc
Formatting ./test/error_handling_for_primitives.cc
Formatting ./test/handlescope.cc
Formatting ./test/async_worker_persistent.cc
Formatting ./test/addon_data.cc
Formatting ./test/addon.cc
Formatting ./test/addon_build/addons/echo addon/addon.cc
Formatting ./test/addon_build/addons/echo-addon/addon.cc
Formatting ./test/addon_build/tpl/addon.cc
Formatting ./test/globalObject/global_object_get_property.cc
Formatting ./test/globalObject/global_object_has_own_property.cc
Formatting ./test/globalObject/global_object_delete_property.cc
Formatting ./test/globalObject/global_object.cc
Formatting ./test/globalObject/global_object_set_property.cc
Formatting ./test/function_reference.cc
Formatting ./test/callbackscope.cc
Formatting ./test/error.cc
Formatting ./test/run_script.cc
Formatting ./napi-inl.deprecated.h
Formatting ./unit-test/generated/binding.cc
Formatting ./napi-inl.h
Formatting ./napi.h

@KevinEady
Copy link
Contributor Author

@KevinEady KevinEady commented Apr 1, 2022

Performed C++ formatting again after a fresh npm install via:

find . -type f -iname '*.cc' -print0 -or -iname '*.h' -print0 | xargs -0 ./node_modules/clang-format/bin/darwin_x64/clang-format -i --verbose --style=file

and provided output:

Formatting [1/81] ./benchmark/property_descriptor.cc
Formatting [2/81] ./benchmark/function_args.cc
Formatting [3/81] ./test/threadsafe_function/threadsafe_function_ctx.cc
Formatting [4/81] ./test/threadsafe_function/threadsafe_function_ptr.cc
Formatting [5/81] ./test/threadsafe_function/threadsafe_function_sum.cc
Formatting [6/81] ./test/threadsafe_function/threadsafe_function_existing_tsfn.cc
Formatting [7/81] ./test/threadsafe_function/threadsafe_function.cc
Formatting [8/81] ./test/threadsafe_function/threadsafe_function_unref.cc
Formatting [9/81] ./test/name.cc
Formatting [10/81] ./test/binding.cc
Formatting [11/81] ./test/external.cc
Formatting [12/81] ./test/thunking_manual.cc
Formatting [13/81] ./test/function.cc
Formatting [14/81] ./test/async_worker.cc
Formatting [15/81] ./test/async_progress_worker.cc
Formatting [16/81] ./test/date.cc
Formatting [17/81] ./test/objectwrap_constructor_exception.cc
Formatting [18/81] ./test/dataview/dataview_read_write.cc
Formatting [19/81] ./test/dataview/dataview.cc
Formatting [20/81] ./test/typed_threadsafe_function/typed_threadsafe_function_unref.cc
Formatting [21/81] ./test/typed_threadsafe_function/typed_threadsafe_function.cc
Formatting [22/81] ./test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc
Formatting [23/81] ./test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc
Formatting [24/81] ./test/typed_threadsafe_function/typed_threadsafe_function_sum.cc
Formatting [25/81] ./test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc
Formatting [26/81] ./test/objectwrap_function.cc
Formatting [27/81] ./test/maybe/check.cc
Formatting [28/81] ./test/reference.cc
Formatting [29/81] ./test/objectwrap.cc
Formatting [30/81] ./test/env_cleanup.cc
Formatting [31/81] ./test/async_progress_queue_worker.cc
Formatting [32/81] ./test/buffer.cc
Formatting [33/81] ./test/basic_types/array.cc
Formatting [34/81] ./test/basic_types/value.cc
Formatting [35/81] ./test/basic_types/number.cc
Formatting [36/81] ./test/basic_types/boolean.cc
Formatting [37/81] ./test/typedarray.cc
Formatting [38/81] ./test/common/test_helper.h
Formatting [39/81] ./test/object_reference.cc
Formatting [40/81] ./test/binding-swallowexcept.cc
Formatting [41/81] ./test/object/object_freeze_seal.cc
Formatting [42/81] ./test/object/subscript_operator.cc
Formatting [43/81] ./test/object/get_property.cc
Formatting [44/81] ./test/object/object_deprecated.cc
Formatting [45/81] ./test/object/set_property.cc
Formatting [46/81] ./test/object/delete_property.cc
Formatting [47/81] ./test/object/has_own_property.cc
Formatting [48/81] ./test/object/has_property.cc
Formatting [49/81] ./test/object/finalizer.cc
Formatting [50/81] ./test/object/object.cc
Formatting [51/81] ./test/movable_callbacks.cc
Formatting [52/81] ./test/async_context.cc
Formatting [53/81] ./test/bigint.cc
Formatting [54/81] ./test/objectwrap_removewrap.cc
Formatting [55/81] ./test/version_management.cc
Formatting [56/81] ./test/objectwrap_multiple_inheritance.cc
Formatting [57/81] ./test/symbol.cc
Formatting [58/81] ./test/array_buffer.cc
Formatting [59/81] ./test/promise.cc
Formatting [60/81] ./test/memory_management.cc
Formatting [61/81] ./test/error_handling_for_primitives.cc
Formatting [62/81] ./test/handlescope.cc
Formatting [63/81] ./test/async_worker_persistent.cc
Formatting [64/81] ./test/addon_data.cc
Formatting [65/81] ./test/addon.cc
Formatting [66/81] ./test/addon_build/addons/echo addon/addon.cc
Formatting [67/81] ./test/addon_build/addons/echo-addon/addon.cc
Formatting [68/81] ./test/addon_build/tpl/addon.cc
Formatting [69/81] ./test/globalObject/global_object_get_property.cc
Formatting [70/81] ./test/globalObject/global_object_has_own_property.cc
Formatting [71/81] ./test/globalObject/global_object_delete_property.cc
Formatting [72/81] ./test/globalObject/global_object.cc
Formatting [73/81] ./test/globalObject/global_object_set_property.cc
Formatting [74/81] ./test/function_reference.cc
Formatting [75/81] ./test/callbackscope.cc
Formatting [76/81] ./test/error.cc
Formatting [77/81] ./test/run_script.cc
Formatting [78/81] ./napi-inl.deprecated.h
Formatting [79/81] ./unit-test/generated/binding.cc
Formatting [80/81] ./napi-inl.h
Formatting [81/81] ./napi.h

Copy link
Member

@mhdawson mhdawson left a comment

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
X Tutup