Giter Site home page Giter Site logo

Let's use jsbeautifier about test262 HOT 12 CLOSED

tc39 avatar tc39 commented on June 14, 2024
Let's use jsbeautifier

from test262.

Comments (12)

michealbenedict avatar michealbenedict commented on June 14, 2024

@rwaldron I thought I'll get the ball rolling on this one, added a gulp task i.e 'beautify'. Attached diff below. Thoughts? Happy to iterate on this based on feedback.

When would be the apt time to run this task? Would it make sense to run this prior to commit? (pre-commit hook), or as a watch task?

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b512c09
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/.hgignore b/.hgignore
index 944d1fb..b0536e7 100644
--- a/.hgignore
+++ b/.hgignore
@@ -2,4 +2,4 @@
 \.d8_history$
 ~$
 \.pyc$
-console/TestCases
+console/TestCases
\ No newline at end of file
diff --git a/gulpfile.js b/gulpfile.js
new file mode 100644
index 0000000..c176c0b
--- /dev/null
+++ b/gulpfile.js
@@ -0,0 +1,37 @@
+var
+  gulp       = require('gulp'),
+  through    = require('through2'),
+  jsBeautify = require('js-beautify').js_beautify;
+
+var
+  beautify = function(opt) {
+  function modifyFile(file, enc, cb) {
+    if (file.isNull()) {
+      this.push(file);
+      return cb();
+    }
+    if (file.isStream()) {
+      this.emit('error', new gutil.PluginError('gulp-beautify', 'Streaming not supported'));
+      return cb();
+    }
+
+    var str = file.contents.toString();
+
+    file.contents = new Buffer(jsBeautify(str, opts));
+    this.push(file);
+    cb();
+  }
+
+  return through.obj(modifyFile);
+};
+
+/*
+ * Beautify task
+**/
+gulp.task('beautify', function() {
+  gulp.src('./test/suite/**/**.js')
+    .pipe(beautify({
+      indentSize: 2,
+      break_chained_methods: false
+    }))
+});
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e2e75f0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,31 @@
+{
+  "name": "test262",
+  "version": "0.0.1",
+  "description": "Official ECMAScript Conformance Test Suite ",
+  "directories": {
+    "docs": "docs",
+    "test": "test"
+  },
+  "devDependencies": {
+    "gulp": "~3.5.0",
+    "gulp-util": "~2.2.13",
+    "through2": "~0.4.1",
+    "js-beautify": "~1.4.2"
+  },
+  "scripts": {
+    "beautify": "gulp beautify"
+  },
+  "repository": {
+    "type": "git",
+    "url": "[email protected]:tc39/test262.git"
+  },
+  "keywords": [
+    "test",
+    "suite",
+    "ecmascript",
+    "ecma"
+  ],
+  "author": "",
+  "license": "Refer LICENSe",
+  "gitHead": "9b669da66c78bd583bc130a7ca3151258e4681a1"
+}

from test262.

rwaldron avatar rwaldron commented on June 14, 2024

@rowoot Thanks, but I'd prefer to use Grunt and have already written the patch.

from test262.

bterlson avatar bterlson commented on June 14, 2024

There is a problem with beautifiers: it may change the test in undesirable ways. For testing library semantics, formatting doesn't matter. But when testing syntax, it's conceivable that the precise placement of braces/spaces/line breaks/etc. are intended and required to exercise syntax of a particular feature...

from test262.

rwaldron avatar rwaldron commented on June 14, 2024

But when testing syntax, it's conceivable that the precise placement of braces/spaces/line breaks/etc. are intended and required to exercise syntax of a particular feature..

Yep, these can be skipped by convention.

from test262.

bterlson avatar bterlson commented on June 14, 2024

What convention do you propose? It seems like before we add any beautification we would need to very carefully understand a large number of current tests to know to exclude them.

from test262.

rwaldron avatar rwaldron commented on June 14, 2024

@bterlson I hadn't thought that far ahead, but I assume any syntax test should have the word "syntax" in the file name. We can omit these with globbing patterns

from test262.

bterlson avatar bterlson commented on June 14, 2024

I do not believe that assumption is correct, as there is currently no convention established for identifying syntax tests... Perhaps the description could contain "syntax" but that's not 100% guaranteed either.

I guess my ultimate point is: any patch for adding beautification should also come with updates applying the convention to the current test collateral.

In terms of convention, I think I'd rather have an @syntax attribute than use filename for some sigils and @-ributes for others.

from test262.

muratsu avatar muratsu commented on June 14, 2024

Another concern with beautifiers is that they may not have the latest language features added yet. I haven't checked the jsbeautifier source but they will probably need some updates before being ES6 compliant.

from test262.

michealbenedict avatar michealbenedict commented on June 14, 2024

@rowoot Thanks, but I'd prefer to use Grunt and have already written the patch.

Sounds good.

from test262.

rwaldron avatar rwaldron commented on June 14, 2024

I do not believe that assumption is correct

That's cool, I just made it up on the spot :P

I guess my ultimate point is: any patch for adding beautification should also come with updates applying the convention to the current test collateral.

Agreed.

In terms of convention, I think I'd rather have an @syntax attribute than use filename for some sigils and @-ributes for others.

In the actual file?

from test262.

bterlson avatar bterlson commented on June 14, 2024

@rwaldron yeah, in the file along with the @path and @Negative attributes. I just think it is better to have all of a test's metadata in one place.

from test262.

bterlson avatar bterlson commented on June 14, 2024

I don't think we should blanket-apply a beautifier, so I'm going to close this. If particular tests are ugly, file a bug. If you want to tackle a broader normalization, file an issue with the normalization you propose so we can consider whether it's appropriate.

from test262.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.